wordpress / latest / functions / _get_term_hierarchy.html

_get_term_hierarchy( string $taxonomy ): array

This function’s access is marked private. This means it is not intended for use by plugin or theme developers, only in other core functions. It is listed here for completeness.

Retrieves children of taxonomy as term IDs.

Parameters

$taxonomy string Required
Taxonomy name.

Return

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

Source

File: wp-includes/taxonomy.php. View all references

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;
}

Uses

Uses Description

Used By

Used By Description

Changelog

Version Description
2.3.0 Introduced.

© 2003–2022 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/functions/_get_term_hierarchy