How to display WordPress posts from a specific category

Please refer the below code for displaying WordPress posts from a specific category.

code

  1. <?php
  2.        
  3.         $the_query = new WP_Query(array(
  4.             'category_name' => 'category_name',
  5.             'post_status' => 'publish',
  6.             'posts_per_page' => 10,
  7.         ));
  8.         ?>
  9.  
  10.         <?php if ($the_query->have_posts()) : ?>
  11.             <?php while ($the_query->have_posts()) : $the_query->the_post(); ?>
  12.                 <?php the_title(); ?>
  13.                 <?php the_excerpt(); ?>
  14.                 <?php the_post_thumbnail(); ?>
  15.                 <?php the_content(); ?>
  16.  
  17.             <?php endwhile; ?>
  18.             <?php wp_reset_postdata(); ?>
  19.  
  20.         <?php else : ?>
  21.             <p><?php __('No Posts found'); ?></p>
  22.         <?php endif; ?>

Leave a Reply

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