How to get all posts related to particular category name?

Just use WP_Query() to generate your custom query, using the category parameters.

Assuming you know (or know how to get) the ID of the specific category, as $catid:

<?php
$category_query_args = array(
    'cat' => $catid
);

$category_query = new WP_Query( $category_query_args );
?>

Note: you could also pass the category slug to the query, via category_name, instead of cat.

Now, just output your loop:

<?php
if ( $category_query->have_posts() ) : while $category_query->have_posts() : $category_query->the_post();
// Loop output goes here
endwhile; endif;
?>

Leave a Comment