Using wp_get_post_terms to separate Parent & Children
-
Hi there.
I’m successfully using
wp_get-post_terms
to list the taxonomies associated with a post on mysingle
template. This is all great.
However, I’d like to list Parents and Children slightly differently.
It’s a music website, so parents are Artists and children are Albums. I’d like to be able to distinguish between the two for clarity to the user.e.g.
Artist/s:$term->name, $term->name2
Album:$child_term
Here’s my current code for reference.
<?php $terms = wp_get_post_terms($post->ID,'hhie_artists'); $count = count($terms); if ( $count > 0 ){ echo "<ul>"; foreach ( $terms as $term ) { echo '<li><a href="'.get_term_link($term->slug, 'hhie_artists').'">'. $term->name . "</a></li>"; } echo "</ul>"; } ?>
I tried using
$child_term = get_term( $term_id, 'category' ); $parent_term = get_term( $child_term->parent, 'artists' );
to no avail.
- The topic ‘Using wp_get_post_terms to separate Parent & Children’ is closed to new replies.