Why do I get Fatal error: Call to undefined function get_most_recent_post_of_user()?

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

Leave a Comment