wp_get_post_revisions

Returns all revisions of specified post.

Description

(array) wp_get_post_revisions( (int) $post_id = 0, (null) $args = null ); 

Returns (array)

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

Parameters (2)

0. $post_id — Optional. (int)
Post ID or WP_Post object. Default is global $post..
1. $args — Optional. (null) => null
Arguments for retrieving post revisions. Default null.

Usage

  1. if ( !function_exists( 'wp_get_post_revisions' ) ) { 
  2. require_once ABSPATH . WPINC . '/revision.php'; 
  3.  
  4. // Optional. Post ID or WP_Post object. Default is global `$post`. 
  5. $post_id = -1; 
  6.  
  7. // Optional. Arguments for retrieving post revisions. Default null. 
  8. $args = null; 
  9.  
  10. // NOTICE! Understand what this does before running. 
  11. $result = wp_get_post_revisions($post_id, $args); 
  12.  

Defined (1)

The function is defined in the following location(s).

/wp-includes/revision.php  
  1. function wp_get_post_revisions( $post_id = 0, $args = null ) { 
  2. $post = get_post( $post_id ); 
  3. if ( ! $post || empty( $post->ID ) ) 
  4. return array(); 
  5.  
  6. $defaults = array( 'order' => 'DESC', 'orderby' => 'date ID', 'check_enabled' => true ); 
  7. $args = wp_parse_args( $args, $defaults ); 
  8.  
  9. if ( $args['check_enabled'] && ! wp_revisions_enabled( $post ) ) 
  10. return array(); 
  11.  
  12. $args = array_merge( $args, array( 'post_parent' => $post->ID, 'post_type' => 'revision', 'post_status' => 'inherit' ) ); 
  13.  
  14. if ( ! $revisions = get_children( $args ) ) 
  15. return array(); 
  16.  
  17. return $revisions;