A WordPress-centric search engine for devs and theme authors



wp_get_post_revision ›

Since2.6.0
Deprecatedn/a
wp_get_post_revision ( $post, $output = OBJECT, $filter = 'raw' )
Parameters: (3)
  • (int|WP_Post) $post The post ID or object.
    Required: Yes
  • (string) $output 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 OBJECT.
    Required: No
    Default: OBJECT
  • (string) $filter Optional sanitation filter. See sanitize_post().
    Required: No
    Default: 'raw'
Returns:
  • (WP_Post|array|null) WP_Post (or array) on success, or null on failure.
Defined at:
Codex:

Gets a post revision.



Source

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

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

	return $revision;
}