3

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

4
  • 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
  • I've just added to the Codex that it only works on Multisite :)
    – Tim Malone
    Jun 23 '16 at 20:04
3

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();

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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