<?php
$genre = get_the_term_list($post->ID, 'genre', '<span >', ', ', '</span>');
$tags = get_the_term_list($post->ID, 'tag-series-movies','<span >', ', ', '</span>');
if($genre,$tags)
echo '<li>Genre: '. $genre . '</li>';
echo '<li>Tags: '. $genre . '</li>';
else {
echo '';
}
?>
Hi. Guys whats wrong of my code? though the code is working 50%. the $genre is working but the else is not working. please help. i want to show the nothing when no genres is not available.
CodePudding user response:
Change if($genre == $genre)
to if($genre){
get_the_term_list
returns the list or false so you just need to check that $genre
is a truthy value
In your current code when $genre
is false you are checking if(false == false)
which always returns true
EDIT:
you can simplify your code like this
if($genre){
echo '<li>Genre: '. $genre . '</li>';
}
if($tags){
echo '<li>Tags: '. $tags . '</li>';
}
There's no need for the else statement as you're not echoing anything