How to Display Posts with a Specific Category in WordPress – Easy Guide

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…

1 min read

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; ?>

Khushal

Welcome to my corner of the web! I'm Khushal Tank, a passionate web developer and the author behind MyProgramming.com. With a robust background in PHP, Webflow, HTML, CSS, and JavaScript, I've dedicated myself to crafting seamless, interactive, and visually appealing websites.

Leave a Reply

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