/** * Manipulate the request to filter media without category * * @since 1.0.1 */ function wp_media_categories_no_category_request($query_args = array()) { // Bail if not in admin if (!is_admin() || !is_main_query()) { return $query_args; } // No category? $media_category = wp_media_categories_get_no_category_search(); // Cuz I'm searchin... if (!empty($media_category) && !empty($query_args[$media_category])) { // No categories, so do a "NOT EXISTS" taxonomy query if ('no_category' === $query_args[$media_category]) { // This is necessary to prevent the JOIN clause from being stomped // and replaced for postmeta $query_args['suppress_filters'] = true; // This adds a taxonomy query, looking for no terms $query_args['tax_query'] = array(array('taxonomy' => $media_category, 'operator' => 'NOT EXISTS', 'include_children' => false)); // Nullify the query argument to prevent incorrect core assertions $query_args[$media_category] = null; } } return $query_args; }
/** * Implement the request to filter media without category * * @since 0.1.0 */ function wp_media_categories_request($query_args = array()) { // No category? $media_category = wp_media_categories_get_no_category_search(); // Cuz I'm searchin... if (!empty($media_category)) { // Find all posts for the current mediaCategory to use for filtering them out $all_attachments = wp_media_categories_get_posts_for_media_taxonomy($media_category); // Post not in? $post_not_in = array(); foreach ($all_attachments as $key => $val) { $post_not_in[] = $val->ID; } $query_args['post__not_in'] = $post_not_in; // Reset the search query parameters to search for all attachments $query_args[$media_category] = 0; } return $query_args; }