_get_term_hierarchy

Retrieves children of taxonomy as Term IDs.

Description

(array) _get_term_hierarchy( (string) $taxonomy ); 

Returns (array)

Empty if $taxonomy isn't hierarchical or returns children as Term IDs.

Parameters (1)

0. $taxonomy (string)
Taxonomy name.

Usage

  1. if ( !function_exists( '_get_term_hierarchy' ) ) { 
  2. require_once ABSPATH . WPINC . '/taxonomy.php'; 
  3.  
  4. // Taxonomy name. 
  5. $taxonomy = ''; 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = _get_term_hierarchy($taxonomy); 
  9.  

Defined (1)

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

/wp-includes/taxonomy.php  
  1. function _get_term_hierarchy( $taxonomy ) { 
  2. if ( !is_taxonomy_hierarchical($taxonomy) ) 
  3. return array(); 
  4. $children = get_option("{$taxonomy}_children"); 
  5.  
  6. if ( is_array($children) ) 
  7. return $children; 
  8. $children = array(); 
  9. $terms = get_terms($taxonomy, array('get' => 'all', 'orderby' => 'id', 'fields' => 'id=>parent')); 
  10. foreach ( $terms as $term_id => $parent ) { 
  11. if ( $parent > 0 ) 
  12. $children[$parent][] = $term_id; 
  13. update_option("{$taxonomy}_children", $children); 
  14.  
  15. return $children;