检索分类的子项作为术语ID。

原型

_get_term_hierarchy( string $taxonomy )

参数

$taxonomy (string) (Required) 分类名称

返回值

(array)  如果$ taxonomy不是分层结构或将子项返回为术语ID,则为空。

源文件

路径:wp-includes/taxonomy.php

<?php
...
 *                          with 1 as value. Default empty array.
 * @return array|WP_Error The subset of $terms that are descendants of $term_id.
 */
function _get_term_children( $term_id, $terms, $taxonomy, &$ancestors = array() ) {
	$empty_array = array();
	if ( empty($terms) )
		return $empty_array;
	$term_list = array();
	$has_children = _get_term_hierarchy($taxonomy);
	if  ( ( 0 != $term_id ) && ! isset($has_children[$term_id]) )
		return $empty_array;
	// Include the term itself in the ancestors array, so we can properly detect when a loop has occurred.
	if ( empty( $ancestors ) ) {
		$ancestors[ $term_id ] = 1;
...
?>

其他

英文文档:https://developer.wordpress.org/reference/functions/_get_term_hierarchy/