wp_get_post_revisions() WordPress Function

The wp_get_post_revisions() function is used to retrieve the revision history for a post. This function can be used to display a list of all the revisions for a post, or to retrieve a specific revision.

wp_get_post_revisions( int|WP_Post $post_id, array|null $args = null ) #

Returns all revisions of specified post.


Description

Top ↑

See also


Top ↑

Parameters

$post_id

(int|WP_Post)(Optional) Post ID or WP_Post object. Default is global $post.

$args

(array|null)(Optional) Arguments for retrieving post revisions.

Default value: null


Top ↑

Return

(array) An array of revisions, or an empty array if none.


Top ↑

More Information

See the parameters section of the WP_Query documentation for a list of parameters that the parameter $args accepts.


Top ↑

Source

File: wp-includes/revision.php

function wp_get_post_revisions( $post_id = 0, $args = null ) {
	$post = get_post( $post_id );
	if ( ! $post || empty( $post->ID ) ) {
		return array();
	}

	$defaults = array(
		'order'         => 'DESC',
		'orderby'       => 'date ID',
		'check_enabled' => true,
	);
	$args     = wp_parse_args( $args, $defaults );

	if ( $args['check_enabled'] && ! wp_revisions_enabled( $post ) ) {
		return array();
	}

	$args = array_merge(
		$args,
		array(
			'post_parent' => $post->ID,
			'post_type'   => 'revision',
			'post_status' => 'inherit',
		)
	);

	$revisions = get_children( $args );
	if ( ! $revisions ) {
		return array();
	}

	return $revisions;
}


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.