Menu Adam R Brown

WP hooks navigation: Home/browseActions indexFilters index

Source View: get_ancestors

To save our bandwidth, we show only a snippet of code around each occurence of the hook. View complete file in SVN (without highlighting).

Understanding Source Code

The best way to understand what a hook does is to look at where it occurs in the source code.

Remember, this hook may occur in more than one file. Moreover, the hook's context may change from version to version.

Source View

This hook occurs 2 times in this file.

Line Code
3305  * @param string $object_type The type of object for which we'll be retrieving ancestors.
3306  * @return array of ancestors from lowest to highest in the hierarchy.
3307  */
3308 function get_ancestors($object_id = 0, $object_type = '') {
3309      $object_id = (int) $object_id;
3310
3311      $ancestors = array();
3312
3313      if ( empty( $object_id ) ) {
3314           return apply_filters('get_ancestors', $ancestors, $object_id, $object_type);
3315      }
3316
3317      if ( is_taxonomy_hierarchical( $object_type ) ) {
3318           $term = get_term($object_id, $object_type);
3319           while ( ! is_wp_error($term) && ! empty( $term->parent ) && ! in_array( $term->parent, $ancestors ) ) {
3320                $ancestors[] = (int) $term->parent;
3321                $term = get_term($term->parent, $object_type);
3322           }
3323      } elseif ( post_type_exists( $object_type ) ) {
3324           $ancestors = get_post_ancestors($object_id);
3325      }
3326
3327      return apply_filters('get_ancestors', $ancestors, $object_id, $object_type);
3328 }
3329
3330 /**
3331  * Returns the term's parent's term_ID
3332  *
3333  * @since 3.1.0
3334  *
3335  * @param int $term_id
3336  * @param string $taxonomy