get_term_children()
最后更新于:2021-11-27 00:55:54
get_term_children( int$term_id, string$taxonomy)Merge all term children into a single array of their IDs.
参数
- $term_id
-
(int) (Required) ID of Term to get children.
- $taxonomy
-
(string) (Required) Taxonomy Name.
响应
(array|GC_Error) List of Term IDs. GC_Error returned if $taxonomy
does not exist.
源文件
文件: gc-includes/taxonomy.php
function get_term_children( $term_id, $taxonomy ) {
if ( ! taxonomy_exists( $taxonomy ) ) {
return new GC_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;
}