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
3913  */
3914 function get_ancestors($object_id = 0, $object_type = '') {
3915      $object_id = (int) $object_id;
3916
3917      $ancestors = array();
3918
3919      if ( empty( $object_id ) ) {
3920
3921           /** This filter is documented in wp-includes/taxonomy.php */
3922           return apply_filters( 'get_ancestors', $ancestors, $object_id, $object_type );
3923      }
3924
3925      if ( is_taxonomy_hierarchical( $object_type ) ) {
3926           $term = get_term($object_id, $object_type);
3927           while ( ! is_wp_error($term) && ! empty( $term->parent ) && ! in_array( $term->parent, $ancestors ) ) {
3928                $ancestors[] = (int) $term->parent;
3929                $term = get_term($term->parent, $object_type);
3930           }
3931      } elseif ( post_type_exists( $object_type ) ) {
 
Line Code
3935      /**
3936       * Filter a given object's ancestors.
3937       *
3938       * @since 3.1.0
3939       *
3940       * @param array  $ancestors   An array of object ancestors.
3941       * @param int    $object_id   Object ID.
3942       * @param string $object_type Type of object.
3943       */
3944      return apply_filters( 'get_ancestors', $ancestors, $object_id, $object_type );
3945 }
3946
3947 /**
3948  * Returns the term's parent's term_ID
3949  *
3950  * @since 3.1.0
3951  *
3952  * @param int $term_id
3953  * @param string $taxonomy