wpseek.com
WordPress开发者和主题制作者的搜索引擎
get_term_children › WordPress Function
Since2.3.0
已弃用n/a
› get_term_children ( $term_id, $taxonomy )
| 参数: (2) |
|
| 返回: |
|
| 定义在: |
|
| 文档: |
Merges all term children into a single array of their IDs.
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.Related Functions: _get_term_children, get_category_children, get_children, get_page_children, get_term_field
源码
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;
}