A WordPress-centric search engine for devs and theme authors



wp_get_post_revisions ›

Since2.6.0
Deprecatedn/a
wp_get_post_revisions ( $post_id = 0, $args = null )
Parameters: (2)
  • (int|WP_Post) $post_id Optional. Post ID or WP_Post object. Default is global `$post`.
    Required: No
    Default:
  • (array|null) $args Optional. Arguments for retrieving post revisions. Default null.
    Required: No
    Default: null
See:
Returns:
  • (array) An array of revisions, or an empty array if none.
Defined at:
Codex:

Returns all revisions of specified post.



Source

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',
		)
	);

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

	return $revisions;
}