WordPress.org

Ready to get started?Download WordPress

Forums

Custom tax_query not working (1 post)

  1. astromono
    Member
    Posted 1 year ago #

    Hi, guys

    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!

    Luis

Topic Closed

This topic has been closed to new replies.

About this Topic