检索在术语ID之前和之后分隔的类别子列表。
原型
get_category_children( int $id, string $before = '/', string $after = '', array $visited = array() )
参数
$id
(int)
(Required)
用于检索子项的类别ID。
$before
(string)
(Optional)
在类别术语ID之前预先添加。
$after
(string)
(Optional)
在类别术语ID后附加。
$visited
(array)
(Optional)
类别已添加的术语ID。
返回值
(string)
源文件
路径:wp-includes/deprecated.php
<?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_wp_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;
}
...
?>
其他
英文文档:https://developer.wordpress.org/reference/functions/get_category_children/