_get_term_hierarchy()
Retrieves children of taxonomy as term IDs.
Эта функция считается внутренней для использования самим ядром. Не рекомендуется использовать эту функцию в своем коде.
Хуков нет.
Возвращает
Массив
. Empty if $taxonomy isn't hierarchical or returns children as term IDs.
Использование
_get_term_hierarchy( $taxonomy );
- $taxonomy(строка) (обязательный)
- Taxonomy name.
Список изменений
С версии 2.3.0 | Введена. |
Код _get_term_hierarchy() get term hierarchy WP 6.1.1
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; }