Find the most recent posts from a specific category

In WordPress sometimes you will want to show the most recent post from a specific category.

To do this use the following code:


global $post;
//change the category=1442 to the category number you want to pull the content from
//change numberposts=1 to the number of posts you want to return from the category
$myposts = get_posts('numberposts=1&category=1442&order=DESC');
foreach($myposts as $post) :
setup_postdata($post);
$catpost= " ". get_the_title() ."";
endforeach;

echo $catpost;

Leave a Reply