I doubt you’re going to find a function that created the exact output you’re using, so you’re probably looking at two nested called to get_terms()
. I usually avoid most other taxonomy-related plugins in favor of get terms. Most of the other functions are wrappers for this one.
Here’s some psuedo-code for what I’d do:
<?php
// Get all the top-level terms i.e. those without a parent
$top_level_terms = get_terms( 'my_taxonomy', array( 'parent' => 0 ) );
foreach( $top_level_terms as $top_term ) {
// get child terms. use parent for direct descendants or child_of for all descendents
$child_terms = get_terms( 'my_taxonomy', array( 'child_of' => $top_term->term_id ));
// list the parent term
printf(
'<a href="https://wordpress.stackexchange.com/questions/81498/%1$s">%2%s</a> (',
esc_url( get_term_link( $top_term->term_id ) ),
esc_attr( $top_term->name )
);
// list all the child terms
foreach ( $child_terms as $child_term ) {
printf(
'<a href="https://wordpress.stackexchange.com/questions/81498/%1$s">%2%s</a>, ',
esc_url( get_term_link( $child_term->term_id ) ),
esc_attr( $child_term->name )
);
}
echo ')';
}
That code’s untested and surely needs some additional arguments from you, but hopefully that can get you started.