WordPress.org

Ready to get started?Download WordPress

Forums

Using wp_get_post_terms to separate Parent & Children (1 post)

  1. hiphopinenglish
    Member
    Posted 9 months ago #

    Hi there.

    I'm successfully using wp_get-post_terms to list the taxonomies associated with a post on my single 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.

Reply

You must log in to post.

About this Topic

  • RSS feed for this topic
  • Started 9 months ago by hiphopinenglish
  • This topic is not resolved
  • WordPress version: 3.6.1