This is my first post, I'm a bit stuck.

I have a custom post (dan) and taxonomy (dnas), with hierarchical categories.

I want to make a query resulting in posts at toplevel (hoofdcategorie01, hoofdcategorie02).

I have the following code that gives me al the posts.

$the_query = new WP_Query( array(
    'post_type' => 'dna',
    'orderby'          => 'title',
    'order'            => 'ASC',
    'tax' => array(
        array (
            'taxonomy' => 'dnas',
            'terms' => $term->term_id,
            'field' => 'term_id',
            'include_children' => false,
            //'terms' => 'politics',
) );

while ( $the_query->have_posts() ) :
            <h4><?php the_title(); ?></h4>


What am I doing wrong?


1 Answer 1


The problem is this:

'tax' => array(

There is no tax option in WP_Query so it's ignored. Did you mean to use tax_query?

  • Thank you Tom for your reply, I now use tax_query. Seems tax was the old way. :) How to get all posts from top level category, but not the sub categories?
    – Dennis
    Commented Oct 2, 2023 at 15:21
  • You're already telling it that, 'include_children' => false,, see the official docs developer.wordpress.org/reference/classes/wp_query/…
    – Tom J Nowell
    Commented Oct 2, 2023 at 15:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.