_get_term_hierarchy

The timeline below displays how wordpress function _get_term_hierarchy has changed across different WordPress versions. If a version is not listed, refer to the next available version below.

WordPress Version: 6.1

//
// Private.
//
/**
 * Retrieves children of taxonomy as term IDs.
 *
 * @access private
 * @since 2.3.0
 *
 * @param string $taxonomy Taxonomy name.
 * @return array Empty if $taxonomy isn't hierarchical or returns children as term IDs.
 */
function _get_term_hierarchy($taxonomy)
{
    if (!is_taxonomy_hierarchical($taxonomy)) {
        return array();
    }
    $children = get_option("{$taxonomy}_children");
    if (is_array($children)) {
        return $children;
    }
    $children = array();
    $terms = get_terms(array('taxonomy' => $taxonomy, 'get' => 'all', 'orderby' => 'id', 'fields' => 'id=>parent', 'update_term_meta_cache' => false));
    foreach ($terms as $term_id => $parent) {
        if ($parent > 0) {
            $children[$parent][] = $term_id;
        }
    }
    update_option("{$taxonomy}_children", $children);
    return $children;
}

WordPress Version: 5.4

//
// Private.
//
/**
 * Retrieves children of taxonomy as Term IDs.
 *
 * @access private
 * @since 2.3.0
 *
 * @param string $taxonomy Taxonomy name.
 * @return array Empty if $taxonomy isn't hierarchical or returns children as Term IDs.
 */
function _get_term_hierarchy($taxonomy)
{
    if (!is_taxonomy_hierarchical($taxonomy)) {
        return array();
    }
    $children = get_option("{$taxonomy}_children");
    if (is_array($children)) {
        return $children;
    }
    $children = array();
    $terms = get_terms(array('taxonomy' => $taxonomy, 'get' => 'all', 'orderby' => 'id', 'fields' => 'id=>parent', 'update_term_meta_cache' => false));
    foreach ($terms as $term_id => $parent) {
        if ($parent > 0) {
            $children[$parent][] = $term_id;
        }
    }
    update_option("{$taxonomy}_children", $children);
    return $children;
}

WordPress Version: 5.3

//
// Private
//
/**
 * Retrieves children of taxonomy as Term IDs.
 *
 * @access private
 * @since 2.3.0
 *
 * @param string $taxonomy Taxonomy name.
 * @return array Empty if $taxonomy isn't hierarchical or returns children as Term IDs.
 */
function _get_term_hierarchy($taxonomy)
{
    if (!is_taxonomy_hierarchical($taxonomy)) {
        return array();
    }
    $children = get_option("{$taxonomy}_children");
    if (is_array($children)) {
        return $children;
    }
    $children = array();
    $terms = get_terms(array('taxonomy' => $taxonomy, 'get' => 'all', 'orderby' => 'id', 'fields' => 'id=>parent', 'update_term_meta_cache' => false));
    foreach ($terms as $term_id => $parent) {
        if ($parent > 0) {
            $children[$parent][] = $term_id;
        }
    }
    update_option("{$taxonomy}_children", $children);
    return $children;
}

WordPress Version: 5.2

//
// Private
//
/**
 * Retrieves children of taxonomy as Term IDs.
 *
 * @access private
 * @since 2.3.0
 *
 * @param string $taxonomy Taxonomy name.
 * @return array Empty if $taxonomy isn't hierarchical or returns children as Term IDs.
 */
function _get_term_hierarchy($taxonomy)
{
    if (!is_taxonomy_hierarchical($taxonomy)) {
        return array();
    }
    $children = get_option("{$taxonomy}_children");
    if (is_array($children)) {
        return $children;
    }
    $children = array();
    $terms = get_terms($taxonomy, array('get' => 'all', 'orderby' => 'id', 'fields' => 'id=>parent', 'update_term_meta_cache' => false));
    foreach ($terms as $term_id => $parent) {
        if ($parent > 0) {
            $children[$parent][] = $term_id;
        }
    }
    update_option("{$taxonomy}_children", $children);
    return $children;
}

WordPress Version: 5.1

//
// Private
//
/**
 * Retrieves children of taxonomy as Term IDs.
 *
 * @ignore
 * @since 2.3.0
 *
 * @param string $taxonomy Taxonomy name.
 * @return array Empty if $taxonomy isn't hierarchical or returns children as Term IDs.
 */
function _get_term_hierarchy($taxonomy)
{
    if (!is_taxonomy_hierarchical($taxonomy)) {
        return array();
    }
    $children = get_option("{$taxonomy}_children");
    if (is_array($children)) {
        return $children;
    }
    $children = array();
    $terms = get_terms($taxonomy, array('get' => 'all', 'orderby' => 'id', 'fields' => 'id=>parent', 'update_term_meta_cache' => false));
    foreach ($terms as $term_id => $parent) {
        if ($parent > 0) {
            $children[$parent][] = $term_id;
        }
    }
    update_option("{$taxonomy}_children", $children);
    return $children;
}

WordPress Version: 4.3

//
// Private
//
/**
 * Retrieves children of taxonomy as Term IDs.
 *
 * @ignore
 * @since 2.3.0
 *
 * @param string $taxonomy Taxonomy name.
 * @return array Empty if $taxonomy isn't hierarchical or returns children as Term IDs.
 */
function _get_term_hierarchy($taxonomy)
{
    if (!is_taxonomy_hierarchical($taxonomy)) {
        return array();
    }
    $children = get_option("{$taxonomy}_children");
    if (is_array($children)) {
        return $children;
    }
    $children = array();
    $terms = get_terms($taxonomy, array('get' => 'all', 'orderby' => 'id', 'fields' => 'id=>parent'));
    foreach ($terms as $term_id => $parent) {
        if ($parent > 0) {
            $children[$parent][] = $term_id;
        }
    }
    update_option("{$taxonomy}_children", $children);
    return $children;
}

WordPress Version: 4.1

//
// Private
//
/**
 * Retrieves children of taxonomy as Term IDs.
 *
 * @access private
 * @since 2.3.0
 *
 * @param string $taxonomy Taxonomy Name
 * @return array Empty if $taxonomy isn't hierarchical or returns children as Term IDs.
 */
function _get_term_hierarchy($taxonomy)
{
    if (!is_taxonomy_hierarchical($taxonomy)) {
        return array();
    }
    $children = get_option("{$taxonomy}_children");
    if (is_array($children)) {
        return $children;
    }
    $children = array();
    $terms = get_terms($taxonomy, array('get' => 'all', 'orderby' => 'id', 'fields' => 'id=>parent'));
    foreach ($terms as $term_id => $parent) {
        if ($parent > 0) {
            $children[$parent][] = $term_id;
        }
    }
    update_option("{$taxonomy}_children", $children);
    return $children;
}

WordPress Version: 3.9

//
// Private
//
/**
 * Retrieves children of taxonomy as Term IDs.
 *
 * @access private
 * @since 2.3.0
 *
 * @uses update_option() Stores all of the children in "$taxonomy_children"
 *	 option. That is the name of the taxonomy, immediately followed by '_children'.
 *
 * @param string $taxonomy Taxonomy Name
 * @return array Empty if $taxonomy isn't hierarchical or returns children as Term IDs.
 */
function _get_term_hierarchy($taxonomy)
{
    if (!is_taxonomy_hierarchical($taxonomy)) {
        return array();
    }
    $children = get_option("{$taxonomy}_children");
    if (is_array($children)) {
        return $children;
    }
    $children = array();
    $terms = get_terms($taxonomy, array('get' => 'all', 'orderby' => 'id', 'fields' => 'id=>parent'));
    foreach ($terms as $term_id => $parent) {
        if ($parent > 0) {
            $children[$parent][] = $term_id;
        }
    }
    update_option("{$taxonomy}_children", $children);
    return $children;
}

WordPress Version: 3.7

//
// Private
//
/**
 * Retrieves children of taxonomy as Term IDs.
 *
 * @package WordPress
 * @subpackage Taxonomy
 * @access private
 * @since 2.3.0
 *
 * @uses update_option() Stores all of the children in "$taxonomy_children"
 *	 option. That is the name of the taxonomy, immediately followed by '_children'.
 *
 * @param string $taxonomy Taxonomy Name
 * @return array Empty if $taxonomy isn't hierarchical or returns children as Term IDs.
 */
function _get_term_hierarchy($taxonomy)
{
    if (!is_taxonomy_hierarchical($taxonomy)) {
        return array();
    }
    $children = get_option("{$taxonomy}_children");
    if (is_array($children)) {
        return $children;
    }
    $children = array();
    $terms = get_terms($taxonomy, array('get' => 'all', 'orderby' => 'id', 'fields' => 'id=>parent'));
    foreach ($terms as $term_id => $parent) {
        if ($parent > 0) {
            $children[$parent][] = $term_id;
        }
    }
    update_option("{$taxonomy}_children", $children);
    return $children;
}