Display WordPress Posts from Specific Category by Category Id or Slug

Do you want to display WordPress Posts from the Specific Category by Category Id?

    $cat_id = 3; 
    $args = array(
       'post_type' => 'post' ,
       'orderby' => 'date' ,
       'order' => 'DESC' ,
       'posts_per_page' => 6,
       'cat'         => $cat_id,
       'paged' => get_query_var('paged'),
       'post_parent' => $parent
   ); 

   $q = new WP_Query($args);
   if ( $q->have_posts() ) { 
     while ( $q->have_posts() ) {
     $q->the_post();
     ?>
       
 

If you want to show posts with category slug instead of category id then

Replace

'cat'         => $cat_id,

with

'category_name' => 'my-category-slug',

Leave a Reply

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