Summery Summery

Retrieve the autosaved data of the specified post.

Syntax Syntax

wp_get_post_autosave( int $post_id, int $user_id )

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.

Return Return

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

Source Source

File: wp-includes/revision.php

	$autosave_name = $post_id . '-autosave-v1';
	$user_id_query = ( 0 !== $user_id ) ? "AND post_author = $user_id" : null;

	// Construct the autosave query.
	$autosave_query = "
		FROM $wpdb->posts
		WHERE post_parent = %d
		AND post_type = 'revision'
		AND post_status = 'inherit'
		AND post_name   = %s " . $user_id_query . '
		ORDER BY post_date DESC
		LIMIT 1';


Changelog Changelog

Version Description
2.6.0 Introduced.


Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.