I have a custom hierarchical taxonomy. I don't know how many nested terms will be in each term.
What I want to do, is to list all taxonomy terms hierarchically no matter how deep each term is nested.
I already know how to do this for each level if I know the depth, but how can I rewrite my code so it will handle unlimited amount of nested terms?
foreach( get_terms( 'tax', array( 'parent' => 0 ) ) as $term ) {
echo $term->name;
foreach( get_terms( 'tax', array( 'parent' => $term->term_id ) ) as $child_term ) {
echo $child_term->name;
// of course I can do more foreach loops here for every lvl...
}
}