Custom tax_query not working
I’m trying to create a page template with a custom taxonomy query that only shows posts from a specific category (the category name is “blog”), but I can’t make it work.
This is the code I have so far:
<?php $category_posts = new WP_query( array( 'orderby' => 'post_date', 'paged' => $paged, 'tax_query' => array( array( 'taxonomy' => 'category', 'field' => 'slug', 'terms' => 'blog' ) ) ) ); ?> <?php if ( $category_posts->have_posts()) : ?> <?php while ( $category_posts->have_posts() ) : $category_posts->the_post(); ?> <?php get_template_part( 'content', get_post_format() ); ?> <?php endwhile; ?>
The above displays posts from all categories and I don’t understand why. Any help you can provide in this regard is much appreciated!
- The topic ‘Custom tax_query not working’ is closed to new replies.