Title: get_most_recent_post_of_user
Published: April 25, 2014
Last modified: May 20, 2026

---

# get_most_recent_post_of_user( int $user_id ): array

## In this article

 * [Description](https://developer.wordpress.org/reference/functions/get_most_recent_post_of_user/?output_format=md#description)
 * [Parameters](https://developer.wordpress.org/reference/functions/get_most_recent_post_of_user/?output_format=md#parameters)
 * [Return](https://developer.wordpress.org/reference/functions/get_most_recent_post_of_user/?output_format=md#return)
 * [Source](https://developer.wordpress.org/reference/functions/get_most_recent_post_of_user/?output_format=md#source)
 * [Related](https://developer.wordpress.org/reference/functions/get_most_recent_post_of_user/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/functions/get_most_recent_post_of_user/?output_format=md#changelog)

[ Back to top](https://developer.wordpress.org/reference/functions/get_most_recent_post_of_user/?output_format=md#wp--skip-link--target)

Gets a user’s most recent post.

## 󠀁[Description](https://developer.wordpress.org/reference/functions/get_most_recent_post_of_user/?output_format=md#description)󠁿

Walks through each of a user’s blogs to find the post with the most recent post_date_gmt.

## 󠀁[Parameters](https://developer.wordpress.org/reference/functions/get_most_recent_post_of_user/?output_format=md#parameters)󠁿

 `$user_id`intrequired

User ID.

## 󠀁[Return](https://developer.wordpress.org/reference/functions/get_most_recent_post_of_user/?output_format=md#return)󠁿

 array Contains the blog_id, post_id, post_date_gmt, and post_gmt_ts.

## 󠀁[Source](https://developer.wordpress.org/reference/functions/get_most_recent_post_of_user/?output_format=md#source)󠁿

    ```php
    function get_most_recent_post_of_user( $user_id ) {
    	global $wpdb;

    	$user_blogs       = get_blogs_of_user( (int) $user_id );
    	$most_recent_post = array();

    	/*
    	 * Walk through each blog and get the most recent post
    	 * published by $user_id.
    	 */
    	foreach ( (array) $user_blogs as $blog ) {
    		$prefix      = $wpdb->get_blog_prefix( $blog->userblog_id );
    		$recent_post = $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", $user_id ), ARRAY_A );

    		// Make sure we found a post.
    		if ( isset( $recent_post['ID'] ) ) {
    			$post_gmt_ts = strtotime( $recent_post['post_date_gmt'] );

    			/*
    			 * If this is the first post checked
    			 * or if this post is newer than the current recent post,
    			 * make it the new most recent post.
    			 */
    			if ( ! isset( $most_recent_post['post_gmt_ts'] ) || ( $post_gmt_ts > $most_recent_post['post_gmt_ts'] ) ) {
    				$most_recent_post = array(
    					'blog_id'       => $blog->userblog_id,
    					'post_id'       => $recent_post['ID'],
    					'post_date_gmt' => $recent_post['post_date_gmt'],
    					'post_gmt_ts'   => $post_gmt_ts,
    				);
    			}
    		}
    	}

    	return $most_recent_post;
    }
    ```

[View all references](https://developer.wordpress.org/reference/files/wp-includes/ms-functions.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/7.0/src/wp-includes/ms-functions.php#L1992)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/7.0/src/wp-includes/ms-functions.php#L1992-L2027)

## 󠀁[Related](https://developer.wordpress.org/reference/functions/get_most_recent_post_of_user/?output_format=md#related)󠁿

| Uses | Description | 
| [get_blogs_of_user()](https://developer.wordpress.org/reference/functions/get_blogs_of_user/)`wp-includes/user.php` |

Gets the sites a user belongs to.

  | 
| [wpdb::get_row()](https://developer.wordpress.org/reference/classes/wpdb/get_row/)`wp-includes/class-wpdb.php` |

Retrieves one row from the database.

  | 
| [wpdb::get_blog_prefix()](https://developer.wordpress.org/reference/classes/wpdb/get_blog_prefix/)`wp-includes/class-wpdb.php` |

Gets blog prefix.

  | 
| [wpdb::prepare()](https://developer.wordpress.org/reference/classes/wpdb/prepare/)`wp-includes/class-wpdb.php` |

Prepares a SQL query for safe execution.

  |

[Show 1 more](https://developer.wordpress.org/reference/functions/get_most_recent_post_of_user/?output_format=md#)
[Show less](https://developer.wordpress.org/reference/functions/get_most_recent_post_of_user/?output_format=md#)

## 󠀁[Changelog](https://developer.wordpress.org/reference/functions/get_most_recent_post_of_user/?output_format=md#changelog)󠁿

| Version | Description | 
| [MU (3.0.0)](https://developer.wordpress.org/reference/since/mu.3.0.0/) | Introduced. |

## User Contributed Notes

You must [log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fget_most_recent_post_of_user%2F)
before being able to contribute a note or feedback.