# get_term_children()

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

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

## Сигнатура

```php
get_term_children( int $term_id, string $taxonomy ): array|WP_Error
```

## Описание

Эта рекурсивная функция объединяет всех потомков $term в один и тот же массив ID терминов. Полезна только для иерархических таксономий.
Вернёт пустой массив, если $term не существует в $taxonomy.

## Параметры

- `$term_id` `int` — обязательный. ID термина, потомков которого нужно получить.
- `$taxonomy` `string` — обязательный. Имя таксономии.

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

`array|WP_Error` — WP_Error $taxonomy

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

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

```php
function get_term_children( $term_id, $taxonomy ) {
	if ( ! taxonomy_exists( $taxonomy ) ) {
		return new WP_Error( 'invalid_taxonomy', __( 'Invalid taxonomy.' ) );
	}

	$term_id = (int) $term_id;

	$terms = _get_term_hierarchy( $taxonomy );

	if ( ! isset( $terms[ $term_id ] ) ) {
		return array();
	}

	$children = $terms[ $term_id ];

	foreach ( (array) $terms[ $term_id ] as $child ) {
		if ( $term_id === $child ) {
			continue;
		}

		if ( isset( $terms[ $child ] ) ) {
			$children = array_merge( $children, get_term_children( $child, $taxonomy ) );
		}
	}

	return $children;
}
```

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

- 2.3.0 — Introduced.

## Связанные

Использует: [`_get_term_hierarchy`](https://chugunov.pro/api-wordpress/functions/_get_term_hierarchy/), [`get_term_children`](https://chugunov.pro/api-wordpress/functions/get_term_children/), [`taxonomy_exists`](https://chugunov.pro/api-wordpress/functions/taxonomy_exists/), [`__`](https://chugunov.pro/api-wordpress/functions/__/), `WP_Error::__construct`.
Используется в: `WP_Term_Query::get_terms`, `WP_Tax_Query::clean_query`, [`get_term_children`](https://chugunov.pro/api-wordpress/functions/get_term_children/).

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