I'm using the function wp_get_recent_posts
to return the latest three posts on a page and I want to get them with their titles, categories, and a brief excerpt. When I look at the documentation on that function, I see that it returns an array of items, but it doesn't say what is available in that array to extract from, so I'm testing by guessing at the names (see this page) - my guess on the post_content was right.
For getting the category, I've tried $recent["category"]
, $recent["the_category"]
, and $recent["post_category"]
and for the excerpt I've tried those as well, except replace category with excerpt. The code I'm using is below:
<?php
$args = array( 'numberposts' => '5' );
$recent_posts = wp_get_recent_posts( $args );
foreach( $recent_posts as $recent ){
echo '<h2><a href="' . get_permalink($recent["ID"]) . '">' . $recent["post_title"].'</a></h2><h3>Posted in '. $recent["the_category"] .'</h3><p>'.$recent["post_content"].'</p>';
}
wp_reset_query();
?>