get_term_children()
Проверено на WordPress 6.9, обновлено Источник: WordPress Developer Resources.
Сигнатура
get_term_children( int $term_id, string $taxonomy ): array|WP_Error
Описание
Эта рекурсивная функция объединяет всех потомков $term в один и тот же массив ID терминов. Полезна только для иерархических таксономий.
Вернёт пустой массив, если $term не существует в $taxonomy.
Оригинал (английский)
This recursive function will merge all of the children of $term into the same array of term IDs. Only useful for taxonomies which are hierarchical.
Will return an empty array if $term does not exist in $taxonomy.
Параметры
$term_id
int
обязательный
$taxonomy
string
обязательный
Возвращаемое значение
array|WP_Error
Исходный код
wp-includes/taxonomy.php:1176
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. |

