这已经得到了回答here
这两个循环都需要存在,您可以随意显示它。
foreach( get_terms( \'products-category\', array( \'hide_empty\' => false, \'parent\' => 0 ) ) as $parent_term ) {
// display top level term name
echo $parent_term->name . \'<br>\';
foreach( get_terms( \'products-category\', array( \'hide_empty\' => false, \'parent\' => $parent_term->term_id ) ) as $child_term ) {
// display name of all childs of the parent term
echo $child_term->name . \'<br>\';
}
}