wp_get_post_autosave( int $post_id, int $user_id )

Retrieve the autosaved data of the specified post.

Description Description

Returns a post object containing the information that was autosaved for the specified post. If the optional $user_id is passed, returns the autosave for that user otherwise returns the latest autosave.

Parameters Parameters


(int) (Required) The post ID.


(int) (Optional) The post author ID.

Top ↑

Return Return

(WP_Post|false) The autosaved data or false on failure or when no autosave exists.

Top ↑

Source Source

File: wp-includes/revision.php

function wp_get_post_autosave( $post_id, $user_id = 0 ) {
	$revisions = wp_get_post_revisions( $post_id, array( 'check_enabled' => false ) );

	foreach ( $revisions as $revision ) {
		if ( false !== strpos( $revision->post_name, "{$post_id}-autosave" ) ) {
			if ( $user_id && $user_id != $revision->post_author ) {

			return $revision;

	return false;

Top ↑

Changelog Changelog

Version Description
2.6.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

You must log in before being able to contribute a note or feedback.