所有深度都使用递归。
function tree() {
$taxName = "custom_tax_name";
$terms = get_terms($taxName, array(\'parent\' => 0, \'fields\' => \'ids\'));
subtree($terms, 0, $taxName);
}
function subtree($children_ids, $parrent_id, $taxName) {
if ( !empty($children_ids) ){
echo \'<ul>\';
foreach($children_ids as $term_child_id) {
$term_child = get_term_by(\'id\', $term_child_id, $taxName);
if ( $term_child->parent == $parrent_id) {
echo \'<li><a href="\' . get_term_link( $term_child->term_id, $taxName ) . \'">\' . $term_child->name . \'</a>\';
$term_children = get_term_children($term_child_id, $taxName);
subtree($term_children, $term_child_id, $taxName);
echo \'</li>\';
}
}
echo \'</ul>\';
}
}