Been trying do this and still no luck. What I'm trying is to list taxonomy terms assigned to a post ordered by parent-child category relationship (hierarchical view).
Structure is something like this
Library = custom post type
Year = custom taxonomy assigned to "library"
- 2021 = parent term
-- April = child term
-- May = child term
-- June = child term
-- July = child term
The desired output is:
2021, April, May, June, July
I tried:
$terms = get_the_terms( $post->ID, 'document_year' );
if ( $terms && ! is_wp_error( $terms ) ) :
$output = array();
foreach ( $terms as $term ) {
$output[] = $term->name;
}
echo '<span>' . implode ( ', ', $output ) . '</span>';
endif;
But this outputs an alphabetical order of terms.
Same with this:
echo ( get_the_term_list( $post->ID, 'category', '', ' / ') );
Any help please?