функция
since 2.3.0
_get_term_hierarchy()
Проверено на WordPress 6.9, обновлено Источник: WordPress Developer Resources.
Сигнатура
_get_term_hierarchy( string $taxonomy ): array
Описание
Возвращает дочерние элементы таксономии в виде ID терминов.
Параметры
$taxonomy
string
обязательный
Имя таксономии.
Возвращаемое значение
array
Исходный код
wp-includes/taxonomy.php:3924
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. |

