wp_get_post_revision

Gets a post revision.

Description

(WP_Post|array|null) wp_get_post_revision( (int|WP_Post) &$post, (constant) $output = OBJECT, (string) $filter = 'raw' ); 

Returns (WP_Post|array|null)

WP_Post (or array) on success, or null on failure.

Parameters (3)

0. $post (int|WP_Post) => &$post
The post ID or object.
1. $output — Optional. (constant) => OBJECT
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.
2. $filter — Optional. (string) => 'raw'
Sanitation filter. See sanitize_post().

Usage

  1. if ( !function_exists( 'wp_get_post_revision' ) ) { 
  2. require_once ABSPATH . WPINC . '/revision.php'; 
  3.  
  4. // The post ID or object. 
  5. $post = &$post; 
  6.  
  7. // Optional. The required return type. One of OBJECT, ARRAY_A, or ARRAY_N, which correspond to 
  8. // a WP_Post object, an associative array, or a numeric array, respectively. Default OBJECT. 
  9. $output = OBJECT; 
  10.  
  11. // Optional sanitation filter. See sanitize_post(). 
  12. $filter = 'raw'; 
  13.  
  14. // NOTICE! Understand what this does before running. 
  15. $result = wp_get_post_revision($post, $output, $filter); 
  16.  

Defined (1)

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

/wp-includes/revision.php  
  1. function wp_get_post_revision(&$post, $output = OBJECT, $filter = 'raw') { 
  2. if ( !$revision = get_post( $post, OBJECT, $filter ) ) 
  3. return $revision; 
  4. if ( 'revision' !== $revision->post_type ) 
  5. return null; 
  6.  
  7. if ( $output == OBJECT ) { 
  8. return $revision; 
  9. } elseif ( $output == ARRAY_A ) { 
  10. $_revision = get_object_vars($revision); 
  11. return $_revision; 
  12. } elseif ( $output == ARRAY_N ) { 
  13. $_revision = array_values(get_object_vars($revision)); 
  14. return $_revision; 
  15.  
  16. return $revision;