Show Post from parent category (custom taxonomy) ONLY!

Any tax_query can take an include_children argument (see Codex) that defaults to true. So just add that to your code and it should work:

<?php
$args = array( 
'posts_per_page' => 100, 
'post_status'   => 'publish', 
'tax_query'     => array(
    array(
        'taxonomy'  => 'ait-dir-item-category',
        'field'     => 'id',
        'terms'     => 75,
        'include_children' => false
    )
), 
'post_type'     => 'ait-dir-item' );
$the_posts = new WP_Query($args);

Note: I’m unsure of the behavior of include_children when a post is assigned to both a child and parent, but I would guess that the post would show up.


EDIT: Posted the wrong link earlier. from The Codex:

include_children (boolean) – Whether or not to include children for hierarchical taxonomies. Defaults to true.

Leave a Comment