I want to display all post under a parent category (custom taxonomy) ONLY!.
Here’s what I’ve done so far:’
<?php
$args = array(
'posts_per_page' => 100,
'post_status' => 'publish',
'tax_query' => array(
array(
'taxonomy' => 'ait-dir-item-category',
'field' => 'id',
'terms' => 75
)
),
'post_type' => 'ait-dir-item' );
$the_posts = new WP_Query($args);
This displays all the posts including the sub categories, which I don’t want to.
Thanks!!
Any
tax_query
can take aninclude_children
argument (see Codex) that defaults totrue
. So just add that to your code and it should work: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: