wp_get_post_revision() WordPress Function

The wp_get_post_revision() function is used to retrieve a specific revision for a given post. This function is useful for restoring a previous version of a post, or for seeing how a post has changed over time.

wp_get_post_revision( int|WP_Post $post, string $output = OBJECT, string $filter = 'raw' ) #

Gets a post revision.


Parameters

$post

(int|WP_Post)(Required)The post ID or object.

$output

(string)(Optional) The required return type. One of OBJECT, ARRAY_A, or ARRAY_N, which correspond to a WP_Post object, an associative array, or a numeric array, respectively.

Default value: OBJECT

$filter

(string)(Optional)sanitation filter. See sanitize_post().

Default value: 'raw'


Top ↑

Return

(WP_Post|array|null) WP_Post (or array) on success, or null on failure.


Top ↑

Source

File: wp-includes/revision.php

function wp_get_post_revision( &$post, $output = OBJECT, $filter = 'raw' ) {
	$revision = get_post( $post, OBJECT, $filter );
	if ( ! $revision ) {
		return $revision;
	}
	if ( 'revision' !== $revision->post_type ) {
		return null;
	}

	if ( OBJECT === $output ) {
		return $revision;
	} elseif ( ARRAY_A === $output ) {
		$_revision = get_object_vars( $revision );
		return $_revision;
	} elseif ( ARRAY_N === $output ) {
		$_revision = array_values( get_object_vars( $revision ) );
		return $_revision;
	}

	return $revision;
}


Top ↑

Changelog

Changelog
VersionDescription
2.6.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.