Exclude post_type from admin comments_list

You’ll need to filter comments_clauses, since WP_Comment_Query only supports a limited post type == X argument. /** * Exclude comments of the “foobar” post type. * * @param array $clauses * @param object $wp_comment_query * @return array */ function wpse_72210_comments_exclude_post_type( $clauses, $wp_comment_query ) { global $wpdb; if ( ! $clauses[‘join’] ) $clauses[‘join’] = “JOIN $wpdb->posts … Read more

How to exclude/filter a tag from get_the_tag_list()

function mytheme_filter_tags( $term_links ) { $result = array(); $exclude_tags = array( ‘some tag’, ‘another tag’, ‘third tag’ ); foreach ( $term_links as $link ) { foreach ( $exclude_tags as $tag ) { if ( stripos( $link, $tag ) !== false ) continue 2; } $result[] = $link; } return $result; } add_filter( “term_links-post_tag”, ‘mytheme_filter_tags’, 100, … Read more

Retrieving custom taxonomy in order, but excluding specific tax IDs

Alas no answers or comments! 😛 Not to worry, a colleague helped me out here and here is the above code working with an $exclude function terms_by_order($taxonomy, $exclude) { global $post; $terms = get_the_terms($post->ID, $taxonomy); // check input if ( empty($terms) || is_wp_error($terms) || !is_array($terms) ) return; // exclude foreach ($terms as $key=>$term) { if … Read more

Excluding a category from next and previous post links

The next_post_link() and previous_post_link() functions have parameteres as follows – $format (string) – You’ve already included this. $link (string) – You’ve already included this. $in_same_term = false (boolean) – Whether or not all linked posts should be within the same taxonomy term. Chances are this should be false if you are looking to exclude a … Read more

Excludes posts that don’t have attachments in the_content()

First, please don’t use query_posts() (emphasis mine)! Note: This function isn’t meant to be used by plugins or themes. As explained later, there are better, more performant options to alter the main query. query_posts() is overly simplistic and problematic way to modify main query of a page by replacing it with new instance of the … Read more

Exclude Tags from get_the_tags

<?php $how_many_posts = 50; $exclude_these_term_ids = array( 10, 20, 35, ); $args = array( ‘posts_per_page’ => $how_many_posts, ‘orderby’ => ‘date’, ‘order’ => ‘DESC’, ); // get the last $how_many_posts, which we will loop over // and gather the tags of query_posts($args); // $temp_ids = array(); while (have_posts()) : the_post(); // get tags for each post … Read more

Exclude ALL posts from sub categories

Don’t change your template, and please do not use query_posts. Add this to your function.php: add_action(‘pre_get_posts’, ‘filter_out_children’); function filter_out_children( $query ) { if ( is_main_query() && is_category() && ! is_admin() ) { $qo = $query->get_queried_object(); $tax_query = array( ‘taxonomy’ => ‘category’, ‘field’ => ‘id’, ‘terms’ => $qo->term_id, ‘include_children’ => false ); $query->set( ‘tax_query’, array($tax_query) ); … Read more

How to filter by category in REST API, excluding posts also in other category term?

According to http://v2.wp-api.org/reference/posts/ you have categories_exclude available as a param to pass to the API. This should work: http://localhost/wp-json/wp/v2/events/?categories=23&categories_exclude=42&per_page=1 …to get the posts from category 23, but exclude those that also have 42 assigned as category.

wp_list_categories exclude not working

The wp_list_categories() function uses get_terms() behind the scenes, where the documentation for the exclude argument says: If $include is non-empty, $exclude is ignored. Instead you could try to exclude the term_id from the include values: $include = wp_filter_object_list( get_the_category(), // Data [ ‘term_id’ => 1 ], // Filter Data ‘NOT’, // Filter Option (exclude) ‘term_id’ … Read more