# _get_term_hierarchy()

URL: https://chugunov.pro/api-wordpress/functions/_get_term_hierarchy/
Проверено на WordPress 6.9, обновлено 06.08.2026.
Источник: независимый русскоязычный справочник chugunov.pro. Не является официальной документацией WordPress.

Тип: функция.
Появился в версии: 2.3.0.

## Сигнатура

```php
_get_term_hierarchy( string $taxonomy ): array
```

## Описание

Возвращает дочерние элементы таксономии в виде ID терминов.

## Параметры

- `$taxonomy` `string` — обязательный. Имя таксономии.

## Возвращаемое значение

`array`

## Исходный код

Файл: `wp-includes/taxonomy.php:3924`

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

## История изменений

- 2.3.0 — Introduced.

## Связанные

Использует: [`get_terms`](https://chugunov.pro/api-wordpress/functions/get_terms/), [`is_taxonomy_hierarchical`](https://chugunov.pro/api-wordpress/functions/is_taxonomy_hierarchical/), [`update_option`](https://chugunov.pro/api-wordpress/functions/update_option/), [`get_option`](https://chugunov.pro/api-wordpress/functions/get_option/).
Используется в: [`clean_taxonomy_cache`](https://chugunov.pro/api-wordpress/functions/clean_taxonomy_cache/), `WP_Term_Query::get_terms`, [`_wp_batch_split_terms`](https://chugunov.pro/api-wordpress/functions/_wp_batch_split_terms/), `WP_Terms_List_Table::display_rows_or_placeholder`, [`_get_term_children`](https://chugunov.pro/api-wordpress/functions/_get_term_children/), [`_pad_term_counts`](https://chugunov.pro/api-wordpress/functions/_pad_term_counts/), [`get_term_children`](https://chugunov.pro/api-wordpress/functions/get_term_children/), [`_wp_menu_item_classes_by_context`](https://chugunov.pro/api-wordpress/functions/_wp_menu_item_classes_by_context/).

Оригинал в официальной документации: https://developer.wordpress.org/reference/functions/_get_term_hierarchy/
