WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

If I have a user's ID, what's the best way for me to get the title of that user's most recent post?

share|improve this question
up vote 5 down vote accepted

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

$recent = get_posts(array(
if( $recent ){
  $title = get_the_title($recent[0]->ID);
  //No published posts

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

share|improve this answer

The best way would be a custom SQL query, but you can simply use the native functions like get_posts() and that would be just fine as well;

$args = array(
    'posts_per_page' => 1,
    'post_author'    => $user_id,
$posts = get_posts( $args );
if ( $posts ) {
    echo $posts[0]->post_title;
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.