I am developing one project and in this project i have to display all the posts related to particular category name.
I have searched a lot but i haven’t got any idea to implement this.
How can i do this so that i can display all the posts from particular category/term
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;
?>