I'm trying to output certain info if the post in in a certain wordpress taxonomy. I have two custom taxonomies "class-content" and "library-topics" although posts that are not attached to anything in "class-content are still outputting the first term of that taxonomy instead of skipping it and outputting the term of "Library-topics" which is what I"m trying to have it do.
// Get the Terms from the Custom Taxonomy Class Content
$terms = get_the_terms($post->ID, 'class-content' );
if($terms){
foreach ( $terms as $term ) {
$class_name = $term->name; // this grabs the hyphenated name
$class_slug = $term->slug; // this grabs the hyphenated slug
}
}
// Get the Terms from the Custom Taxonomy Library Topics
$terms = get_the_terms($post->ID, 'library-topics' );
if($terms){
foreach ( $terms as $term ) {
$topic_name = $term->name; // this grabs the hyphenated name
}
}
// If statement for if there is a term for class or topic taxonomy than assign them to variables
if ($class_name) {
$class_name_pr = ' '. $class_name .' ';
} else{
$class_name_pr = ' '. $topic_name .' ';
}
Than in my loop I have this
<?php echo $class_name_pr; ?>
The posts that are in the "class-content" taxonomy works fine but the ones that are in the "library-topics" are outputting the first term of "class-content".
To see the issue in action if you view this page http://hearthable.com/library/page/3/ you'll see the name "druid" in orange under all the posts. Although that "druid" term is in the "class-content" taxonomy and those posts are not listed under the "class-content" taxonomy. They are in the "library-topic" taxonomy and the term they are under in "library-topic" should be displayed instead of druid.