wpseek.com
Eine auf WordPress spezialiserte Suchmaschine für Entwickler und Theme-Autoren
get_ancestors [ WordPress Function ]
| Parameter: |
|
| Gibt zurück: |
|
| Definiert in: |
|
Get an array of ancestor IDs for a given object.
Source
<?php
function get_ancestors($object_id = 0, $object_type = '') {
$object_id = (int) $object_id;
$ancestors = array();
if ( empty( $object_id ) ) {
return apply_filters('get_ancestors', $ancestors, $object_id, $object_type);
}
if ( is_taxonomy_hierarchical( $object_type ) ) {
$term = get_term($object_id, $object_type);
while ( ! is_wp_error($term) && ! empty( $term->parent ) && ! in_array( $term->parent, $ancestors ) ) {
$ancestors[] = (int) $term->parent;
$term = get_term($term->parent, $object_type);
}
} elseif ( null !== get_post_type_object( $object_type ) ) {
$object = get_post($object_id);
if ( ! is_wp_error( $object ) && isset( $object->ancestors ) && is_array( $object->ancestors ) )
$ancestors = $object->ancestors;
else {
while ( ! is_wp_error($object) && ! empty( $object->post_parent ) && ! in_array( $object->post_parent, $ancestors ) ) {
$ancestors[] = (int) $object->post_parent;
$object = get_post($object->post_parent);
}
}
}
return apply_filters('get_ancestors', $ancestors, $object_id, $object_type);
}
?>
Beispiele [ wp-snippets.com ]
Top Google Suchergebnisse
- Function Reference/get ancestors « WordPress Codex
Description. Returns an array containing the parents of the given object. Usage. < ?php get_ancestors( $object_id, $object_type ); ?> Default Usage ...
codex.wordpress.org - WordPress › Support » Help! get_ancestors not working...
Help! get_ancestors not working... (9 posts). AlfietheCoder. Member Posted 2 years ago #. I've recently taken the plunge and upgraded my version 2.5 to 2.9.
wordpress.org - #12443 (General get_ancestors() function) – WordPress Trac
get_ancestors([object_id], [object_type]) returns an array of the ancestor objects, ... if ( in_array(123, get_ancestors(456, 'page') ) ) { // highlight a menu item, ...
core.trac.wordpress.org - get_ancestors | A HitchHackers guide through WordPress
Feb 24, 2011 ... function get_ancestors($object_id = 0, $object_type = '') { $object_id = (int) $ object_id; $ancestors = array(); if ( empty( $object_id ) ) { return ...
hitchhackerguide.com