get_category_children()
最后更新于:2021-11-26 07:10:20
get_category_children( int$id, string$before=’/’, string$after=”, array$visited=array())Retrieve category children list separated before and after the term IDs.
参数
- $id
-
(int) (Required) Category ID to retrieve children.
- $before
-
(string) (Optional) Prepend before category term ID.
Default value: ‘/’
- $after
-
(string) (Optional) Append after category term ID.
Default value: ”
- $visited
-
(array) (Optional) Category Term IDs that have already been added.
Default value: array()
响应
(string)
源文件
文件: gc-includes/deprecated.php
function get_category_children( $id, $before = '/', $after = '', $visited = array() ) {
_deprecated_function( __FUNCTION__, '2.8.0', 'get_term_children()' );
if ( 0 == $id )
return '';
$chain = '';
/** TODO: Consult hierarchy */
$cat_ids = get_all_category_ids();
foreach ( (array) $cat_ids as $cat_id ) {
if ( $cat_id == $id )
continue;
$category = get_category( $cat_id );
if ( is_gc_error( $category ) )
return $category;
if ( $category->parent == $id && !in_array( $category->term_id, $visited ) ) {
$visited[] = $category->term_id;
$chain .= $before.$category->term_id.$after;
$chain .= get_category_children( $category->term_id, $before, $after );
}
}
return $chain;
}