admin管理员组

文章数量:1133768

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.

    <?php
        
        
$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() ) :
    $the_query->the_post();
            
        ?>
            <h4><?php the_title(); ?></h4>
            <?php
            
endwhile;

wp_reset_postdata();
            
            
?>

What am I doing wrong?

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.

    <?php
        
        
$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() ) :
    $the_query->the_post();
            
        ?>
            <h4><?php the_title(); ?></h4>
            <?php
            
endwhile;

wp_reset_postdata();
            
            
?>

What am I doing wrong?

Share Improve this question asked Oct 2, 2023 at 10:31 DennisDennis 1
Add a comment  | 

1 Answer 1

Reset to default 0

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?

本文标签: Query top level custom post in taxonomy