wp_get_post_revisions()
Returns all revisions of specified post.
Uses: get_children()
No Hooks.
Return
WP_Post[]|Int[]
. Array of revision objects or IDs, or an empty array if none.
Usage
wp_get_post_revisions( $post, $args );
- $post(int|WP_Post)
- Post ID or WP_Post object.
Default: global $post - $args(array|null)
- Arguments for retrieving post revisions.
Default: null
Examples
#1 Get the latest revision of the post
$post_id = 999; $revisions = wp_get_post_revisions( $post_id ); $last_revision = false; // Get the latest version but not the autosave foreach ( $revisions as $revision ) { if ( false !== strpos( $revision->post_name, "{$revision->post_parent}-revision" ) ) { $last_revision = $revision; break; } }
#2 An example of what the function outputs
$revisions = wp_get_post_revisions( 128 ); /* revision posts 128 Array ( [22] => WP_Post Object ( [ID] => 22 [post_author] => 0 [post_date] => 2017-02-21 01:41:45 [post_date_gmt] => 2017-02-20 22:41:45 [post_content] => Content of revision ... [post_title] => Ice Cream Recipe [post_excerpt] => [post_status] => inherit [comment_status] => closed [ping_status] => closed [post_password] => [post_name] => 128-revision-v1 [to_ping] => [pinged] => [post_modified] => 2017-02-21 01:41:45 [post_modified_gmt] => 2017-02-20 22:41:45 [post_content_filtered] => [post_parent] => 128 [guid] => http://example.com/recept-morojenogo/128-revision-v1.html [menu_order] => 0 [post_type] => revision [post_mime_type] => [comment_count] => 0 [filter] => raw ) [19] => WP_Post Object ( [ID] => 19 [post_author] => 0 [post_date] => 2017-02-19 15:40:48 [post_date_gmt] => 2017-02-19 12:40:48 [post_content] => Revision content ... [post_title] => Ice Cream Recipe [post_excerpt] => [post_status] => inherit [comment_status] => closed [ping_status] => closed [post_password] => [post_name] => 128-revision-v1 [to_ping] => [pinged] => [post_modified] => 2017-02-19 15:40:48 [post_modified_gmt] => 2017-02-19 12:40:48 [post_content_filtered] => [post_parent] => 128 [guid] => http://example.com/recept-morojenogo/128-revision-v1.html [menu_order] => 0 [post_type] => revision [post_mime_type] => [comment_count] => 0 [filter] => raw ) [12] => WP_Post Object ( ... ) ) */
Notes
- See: get_children()
Changelog
Since 2.6.0 | Introduced. |