jetpack_get_term_parents

Return the parents for a given taxonomy term ID.

Description

(string) jetpack_get_term_parents( (int) $term, (string) $taxonomy, (array) $visited = array() ); 

Returns (string)

A list of links to the term parents.

Parameters (3)

0. $term (int)
Taxonomy term whose parents will be returned.
1. $taxonomy (string)
Taxonomy name that the term belongs to.
2. $visited — Optional. (array) => array()
Terms already added to prevent duplicates.

Usage

  1. if ( !function_exists( 'jetpack_get_term_parents' ) ) { 
  2. require_once '/modules/theme-tools/site-breadcrumbs.php'; 
  3.  
  4. // Taxonomy term whose parents will be returned. 
  5. $term = -1; 
  6.  
  7. // Taxonomy name that the term belongs to. 
  8. $taxonomy = ''; 
  9.  
  10. // Terms already added to prevent duplicates. 
  11. $visited = array(); 
  12.  
  13. // NOTICE! Understand what this does before running. 
  14. $result = jetpack_get_term_parents($term, $taxonomy, $visited); 
  15.  

Defined (1)

The function is defined in the following location(s).

/modules/theme-tools/site-breadcrumbs.php  
  1. function jetpack_get_term_parents( $term, $taxonomy, $visited = array() ) { 
  2. $parent = get_term( $term, $taxonomy ); 
  3.  
  4. if ( is_wp_error( $parent ) ) { 
  5. return $parent; 
  6.  
  7. $chain = ''; 
  8.  
  9. if ( $parent->parent && ( $parent->parent != $parent->term_id ) && ! in_array( $parent->parent, $visited ) ) { 
  10. $visited[] = $parent->parent; 
  11. $chain .= jetpack_get_term_parents( $parent->parent, $taxonomy, $visited ); 
  12.  
  13. $chain .= '<a href="' . esc_url( get_category_link( $parent->term_id ) ) . '">' . $parent->name . '</a>'; 
  14.  
  15. return $chain;