Website Building » WordPress » How do I show recent posts from a specific category in WordPress?

How do I show recent posts from a specific category in WordPress?

Last updated on September 25, 2022 @ 12:47 am

In order to show posts from a specific category in WordPress, you can use the wp_categories() function. This function takes an array of category names as its parameter, and returns an object with the categories’ posts listed. To show the posts from the “Travel” category in WordPress, you would use the following code:

wp_categories( ‘Travel’ );

The output from this code would look something like this:

Array ( [0] => WP_Post Object ( [ID] => 7 [post_author] => 1 [post_date] => 2018-01-25 15:02:00 [post_date_gmt] => 2018-01-25 15:02:00 [post_content] =>

Looking for a new travel destination? Check out our latest post about visiting Barcelona!

[post_title] => Barcelona: A Unique and Fascinating City [post_excerpt] =>

Barcelona is a unique and fascinating city, and we highly recommend a visit! In this post, we’ll discuss some of the highlights of this amazing city, and why you should add it to your travel itinerary.

[category] => Travel [post_mime_type] => [comment_status] => open [ping_status] => open [post_password] => [post_name] => barcelona-a-unique-and-fascinating-city [to_ping] => [pinged] => [post_modified] => 2018-01-25 15:02:00 [post_modified_gmt] => 2018-01-25 15:02:00 [post_content_filtered] => [post_parent] => 0 [guid] => http://wpcooks.com/?p=7 [menu_order] => 0 [post_type] => post [post_mime_type] => [comment_count] => 0 [filter] => raw ) [1] => WP_Post Object ( [ID] => 8 [post_author] => 1 [post_date] => 2018-01-25 15:02:00 [post_date_gmt] => 2018-01-25 15:02:00 [post_content] =>

PRO TIP: If you are not careful, displaying recent posts from a specific category on your WordPress site can result in duplicate content penalties from search engines. This is because the same content will be accessible via multiple URLs.

Looking for a new travel destination? Check out our latest post about visiting Tokyo!

[post_title] => Tokyo: A Unique and Fascinating City [post_excerpt] =>

Tokyo is a unique and fascinating city, and we highly recommend a visit! In this post, we’ll discuss some of the highlights of this amazing city, and why you should add it to your travel itinerary.

[category] => Travel [post_mime_type] => [comment_status] => open [ping_status] => open [post_password] => [post_name] => tokyo-a-unique-and-fascinating-city [to_ping] => [pinged] => [post_modified] => 2018-01-25 15:02:00 [post_modified_gmt] => 2018-01-25 15:02:00 [post_content_filtered] => [post_parent] => 0 [guid] => http://wpcooks.com/?p=8 [menu_order] => 1 [post_type] => post [post_mime_type] => [comment_count] => 0 [filter] => raw ) [2] => WP_Post Object ( [ID] => 9 [post_author] => 1 [post_date] => 2018-01-25 15:02:00 [post_date_gmt] => 2018-01-25 15:02:00 [post_content] =>

Looking for a new travel destination? Check out our latest post about visiting Bali!

[post_title] => Bali: A Unique and Fascinating Island Destination [post_excerpt] =>

Bali is a unique and fascinating island destination, and we highly recommend a visit! In this post, we’ll discuss some of the highlights of this amazing island, and why you should add it to your travel itinerary.

[category] => Travel [post_mime_type] => [comment_status] => open [ping_status] => open [post_password] => [post_name] => bali-a-unique-and-fascinating-island-destination [to_ping] => [pinged] => [post_modified] => 2018-01-25 15:02:00 [post_modified_gmt] => 2018-01-25 15:02:00 [post.
Kathy McFarland

Kathy McFarland

Devops woman in trade, tech explorer and problem navigator.