I use Custom Taxonomy "Artists" to differentiate between "Albums" (Parent Taxonomy) and "Albums" (belonging to an Artist, Child Taxonomy).
I am showing my taxonomy on posts for users to see which Artist and Album is associated with each post. My code is working fine in some cases, but in others, it doesn't differentiate correctly between Parent (Artists) and Child (Album) (Children show as Parents). Here is what I'm using at the moment. How can I improve it to avoid my issue?
$_terms = wp_get_post_terms($post->ID, 'hhie_artists');
if (!empty ($_terms)):
echo "In this Article: ";
echo "Artist/s: ";
foreach ($_terms as $_term) {
if ($_term->parent == 0) //check for parent terms only
'<a href=' . get_term_link($_term) . '>' . $_term->name . '</a> | ';
if ($_term->parent > 0) //check for children
echo 'Album: <a href=' . get_term_link($_term) . '>' . $_term->name . '</a>';
}
endif;`
Note: There will be a max of one album per post.
EDIT: Sorry for lack of clarity. I get things like this returned:
Artist/s: Album: A Year In The Life Of Oscar The SlouchRamson Badbonez |
(Should be: Artist/s: Ramson Badbonez | Album: A Year In The Life Of Oscar The Slouch) This doesn't always happen though. Sometimes it shows correctly.
In the case of multiple artists: Artist/s: Album: Dabbla JehstHeavy Ear Play
(Should be: Artist/s: Dabbla Jehst | Album: Heavy Ear Play)