I want to list titles of the default WP posts of "blog" category in my blog page, which has "Blog" title and uses page-blog.php as template with the following code in it:
<article> <?php $args = array ( 'post_type' => 'post', 'category_name' => 'blog' ); $query = new WP_Query( $args ); if ( $query->have_posts() ) : while ( $query->have_posts() ) : $query- >the_post(); ?> <h1><?php the_title(); ?></h1> <?php endwhile; wp_reset_postdata(); else : ?> <p><?php _e( 'Sorry, no posts matched your criteria.' ); ?></p> <?php endif; ?> </article>
No matter what I try it keeps showing all WP posts, regardless to which category they assigned to... even though the same code works perfectly with my custom post types...
Please help! Thanks.