Get a user’s most recent post title

You just set the ‘author’ parameter in a WP_Query query or get_posts (which accepts the same parameters):

$recent = get_posts(array(
    'author'=>1,
    'orderby'=>'date',
    'order'=>'desc',
    'numberposts'=>1
));
if( $recent ){
  $title = get_the_title($recent[0]->ID);
}else{
  //No published posts
}

(Note the ‘orderby’ and ‘order’ here are redundant because they are set to their default values, but you get the idea)

Leave a Comment

tech