Beginner's Guide for WordPress - Start your WordPress Blog in minutes.
Choosing the Best
WordPress Hosting
How to Easily
Install WordPress
WordPress Plugins
View all Guides

How to Display Recent Posts From A Specific Category In WordPress

Last updated on by
Special WordPress Hosting offer for WPBeginner Readers
How to Display Recent Posts From A Specific Category In WordPress

For advance users who want to display recent posts from a specific category, we have this article specially for you. Beginner users will most likely not use this. This tutorial is mostly used in creating magazine style themes.

$catquery = new WP_Query( 'cat=3&posts_per_page=10' );
while($catquery->have_posts()) : $catquery->the_post();
<li><h3><a href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a></h3>

<ul><li><?php the_content(); ?></li>
<?php endwhile; ?>

At the top where it says showpost= change the number to how many posts you want to display, and cat=3 is the id of the category, so change the ID of the category to pick which category will you be displaying.

A live example of this tutorial in action is at

The news style format where it displays recent news from each category is accomplished using the code above.

Editorial Staff at WPBeginner is a team of WordPress experts led by Syed Balkhi. Page maintained by Syed Balkhi.

WPBeginner's Video Icon
Our HD-Quality tutorial videos for WordPress Beginners will teach you how to use WordPress to create and manage your own website in about an hour. Get started now »


  1. Md. Abul Kalam Azad says:

    I knew it but forgot. I tried it and it worked well. Thanks

  2. hostelised says:

    how to use this code? can i use this in a widget? or i have to create another page to use this code?

  3. Guest says:

    Hi, with this code, i alway get the same image, i tested and added the title and i alway get the same title.

  4. John says:

    problem with the pagination of posts. Any solution?

  5. Arjun S Kumar says:

    Can I make a shortcode using this code and use it in a page?

  6. Alex Leeson-Brown says:

    I just thought you should know that this code broke the comments on my site. It made it so that every post had the same comments throughout the whole blog

  7. sai says:

    Thanks a lot…

  8. Diane Bourque says:

    Thanks so much for this code. It worked perfectly for me. I needed to show only one post from one category on one particular page and this did it! Thanks again.

  9. 1joshmay says:

    How could I include a thumbnail of each post to this?

  10. RichardGauthier says:

    Is there a way to put that code or whatever something similar, in the sidebar?

  11. ibadullah25 says:

    @wpbeginner Yes, I am using a magazine style theme I paste it in the single.php I want to display in posts not on the index page and the code is not have closing tags?

  12. wpbeginner says:

    @ibadullah25 Paste the code in the file where you want to display this… Usually a code like this is used in magazine style themes often on the homepage.

  13. ibadullah25 says:

    How this code works?

    I mean where should I paste this?

  14. yair says:

    the site mentioned above was built as part of experimental project. it was built from scratch with no modifications what so ever.

    Lately, after discovering you helpful site (you guys are doing well here), i used the code mentioned here and then funny thing happened; it took over the title (the title changed to ‘Reviews’ – reviews is the category im pulling) . the title before that was fine and when I remove the code the title is going back to normal… i should mention that i’m using also All in One SEO…
    any thoughts??

    thanks you for your time!

Add a Comment

We're glad you have chosen to leave a comment. Please keep in mind that all comments are moderated according to our comment policy, and all links are nofollow. Do NOT use keywords in the name field. Let's have a personal and meaningful conversation.