_get_post_ancestors

Retrieve post ancestors.

Description

_get_post_ancestors( (WP_Post) &$post ); 

This is no longer needed as WP_Post lazy-loads the ancestors property with get_post_ancestors().

Parameters (1)

0. $post (WP_Post) => &$post
&$post Post object, passed by reference (unused).

Usage

  1. if ( !function_exists( '_get_post_ancestors' ) ) { 
  2. require_once ABSPATH . WPINC . '/deprecated.php'; 
  3.  
  4. // &$post Post object, passed by reference (unused). 
  5. $post = &$post; 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = _get_post_ancestors($post); 
  9.  

Defined (2)

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

/wp-includes/deprecated.php  
  1. function _get_post_ancestors( &$post ) { 
  2. _deprecated_function( __FUNCTION__, '3.5.0' ); 
/wp-includes/post.php  
  1. function get_post_ancestors( $post ) { 
  2. $post = get_post( $post ); 
  3.  
  4. if ( ! $post || empty( $post->post_parent ) || $post->post_parent == $post->ID ) 
  5. return array(); 
  6.  
  7. $ancestors = array(); 
  8.  
  9. $id = $ancestors[] = $post->post_parent; 
  10.  
  11. while ( $ancestor = get_post( $id ) ) { 
  12. // Loop detection: If the ancestor has been seen before, break. 
  13. if ( empty( $ancestor->post_parent ) || ( $ancestor->post_parent == $post->ID ) || in_array( $ancestor->post_parent, $ancestors ) ) 
  14. break; 
  15.  
  16. $id = $ancestors[] = $ancestor->post_parent; 
  17.  
  18. return $ancestors;