get_term_children 源码的疑问:if ( $term_id == $child ) 自己会是自己的子项?
moliu 2015-11-27 10:07:09 * @param string $term_id ID of Term to get children.
* @param string $taxonomy Taxonomy Name.
* @return array|WP_Error List of Term IDs. WP_Error returned if `$taxonomy` does not exist.
*/
function get_term_children( $term_id, $taxonomy ) {
if ( ! taxonomy_exists($taxonomy) )
return new WP_Error('invalid_taxonomy', __('Invalid taxonomy'));
$term_id = intval( $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;
}