wpseek.com
Eine auf WordPress spezialiserte Suchmaschine für Entwickler und Theme-Autoren
get_post_ancestors › WordPress Function
Seit2.5.0
Veraltetn/v
› get_post_ancestors ( $post )
| Parameter: |
|
| Gibt zurück: |
|
| Definiert in: |
|
| Codex: |
Retrieves the IDs of the ancestors of a post.
Ähnliche Funktionen: _get_post_ancestors, get_ancestors, get_post_custom, get_post_class, get_post_custom_keys
Quellcode
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 = $post->post_parent;
$ancestors[] = $id;
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, true )
) {
break;
}
$id = $ancestor->post_parent;
$ancestors[] = $id;
}
return $ancestors;
}