How to Display Posts with a Specific Category


In this blog we will discuss how to display posts with specific categories.

To show Specific Category post in WordPress we have to enter category_name in array

Below is the code for how to post a specific category in WordPress.

<?php
$args = array(
'post_type' => 'post', 
'order' => 'DESC',
'category_name' => 'enter-your-category-name'
);
$the_query = new WP_Query( $args ); ?>

<?php if ( $the_query->have_posts() ) : ?> 
<?php while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
 
<?php the_title(); ?> 
 
<?php endwhile; ?>
<?php wp_reset_postdata(); ?>
<?php endif; ?>

Related Posts

Leave a Reply

Your email address will not be published. Required fields are marked *