_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
if ( !function_exists( '_get_post_ancestors' ) ) { require_once ABSPATH . WPINC . '/deprecated.php'; } // &$post Post object, passed by reference (unused). $post = &$post; // NOTICE! Understand what this does before running. $result = _get_post_ancestors($post);
Defined (2)
The function is defined in the following location(s).
- /wp-includes/deprecated.php
- function _get_post_ancestors( &$post ) {
- _deprecated_function( __FUNCTION__, '3.5.0' );
- }
- /wp-includes/post.php
- function get_post_ancestors( $post ) {
- $post = get_post( $post );
- if ( ! $post || empty( $post->post_parent ) || $post->post_parent == $post->ID )
- return array();
- $ancestors = array();
- $id = $ancestors[] = $post->post_parent;
- while ( $ancestor = get_post( $id ) ) {
- // Loop detection: If the ancestor has been seen before, break.
- if ( empty( $ancestor->post_parent ) || ( $ancestor->post_parent == $post->ID ) || in_array( $ancestor->post_parent, $ancestors ) )
- break;
- $id = $ancestors[] = $ancestor->post_parent;
- }
- return $ancestors;
- }