get_posts assigned to a specific custom taxonomy term, and not the term’s children

In looking at the WP_Tax_Query class in /wp-includes/taxonomy.php, I found that there is a ‘include_children’ option which defaults to true. I modified my original get_posts() call with the following, and it works great: $pages = get_posts(array( ‘post_type’ => ‘page’, ‘numberposts’ => -1, ‘tax_query’ => array( array( ‘taxonomy’ => ‘taxonomy-name’, ‘field’ => ‘term_id’, ‘terms’ => 1, … Read more

How do I exclude a custom taxonomy from the post loop

You would want to use the NOT EXISTS operator along with passing the taxonomy slug, which tells the query not to include any of a chosen category from your custom taxonomy inside the loop. To exclude all posts that are in the taxonomy “fruit” (regardless of fruit kind), here is the snippet: $args = array( … Read more

“tax_query” parameter not working with WP_Query

The tax_query parameter is an array of arrays, not just an array. This: ‘tax_query’ => array( ‘taxonomy’ => ‘video_type’, ‘terms’ => ‘episode’, ‘field’ => ‘slug’, ‘include_children’ => true, ‘operator’ => ‘IN’ ), Should instead be this: ‘tax_query’ => array( array( ‘taxonomy’ => ‘video_type’, ‘terms’ => ‘episode’, ‘field’ => ‘slug’, ‘include_children’ => true, ‘operator’ => ‘IN’ … Read more