Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I am using WordPress 3.4.2. The codex doesn't say anything about this function being depreciated: http://codex.wordpress.org/Function_Reference/get_most_recent_post_of_user

share|improve this question
    
Are you using multisite? –  Chris_O Sep 29 '12 at 23:09
    
No, I am not using multisite. –  rg89 Sep 29 '12 at 23:10
1  
deprecated, rather than depreciated :) –  Ivan Sep 30 '12 at 1:44
add comment

1 Answer 1

up vote 1 down vote accepted

get_most_recent_post_of_user() is for multisite installs to get the most recent post of the user from each blog.

Here is a comparable function you can use that will return the post object of the defined users most recent post.

function wpse_get_user_recent( $user ) {
    global $wpdb;

    $recent  = $wpdb->get_row( $wpdb->prepare("SELECT ID, post_date_gmt FROM {$prefix}posts WHERE post_author = %d AND post_type = 'post' AND post_status = 'publish' ORDER BY post_date_gmt DESC LIMIT 1", (int)$user ), ARRAY_A);

        if( ! isset( $recent['ID'] ) )
            return new WP_Error( 'No post found for selected user' );

    return get_post( $recent['ID'], 'ARRAY_A' );

}

Usage:

$post = wpse_get_user_recent( 36 );
setup_post_data( $post );

the_title();
the_content();
wp_reset_postdata();
share|improve this answer
add comment

Your Answer

 
discard

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.