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
3052  * @param string $object_type The type of object for which we'll be retrieving ancestors.
3053  * @return array of ancestors from lowest to highest in the hierarchy.
3054  */
3055 function get_ancestors($object_id = 0, $object_type = '') {
3056      $object_id = (int) $object_id;
3057
3058      $ancestors = array();
3059
3060      if ( empty( $object_id ) ) {
3061           return apply_filters('get_ancestors', $ancestors, $object_id, $object_type);
3062      }
3063
3064      if ( is_taxonomy_hierarchical( $object_type ) ) {
3065           $term = get_term($object_id, $object_type);
3066           while ( ! is_wp_error($term) && ! empty( $term->parent ) && ! in_array( $term->parent, $ancestors ) ) {
3067                $ancestors[] = (int) $term->parent;
3068                $term = get_term($term->parent, $object_type);
3069           }
3070      } elseif ( null !== get_post_type_object( $object_type ) ) {
 
Line Code
3073                $ancestors = $object->ancestors;
3074           else {
3075                while ( ! is_wp_error($object) && ! empty( $object->post_parent ) && ! in_array( $object->post_parent, $ancestors ) ) {
3076                     $ancestors[] = (int) $object->post_parent;
3077                     $object = get_post($object->post_parent);
3078                }
3079           }
3080      }
3081
3082      return apply_filters('get_ancestors', $ancestors, $object_id, $object_type);
3083 }
3084
3085 /**
3086  * Returns the term's parent's term_ID
3087  *
3088  * @since 3.1.0
3089  *
3090  * @param int $term_id
3091  * @param string $taxonomy