I have a select field that allows me to choose either yes and no but when I try to output it, I get only the select option duplicated…
Code I’m using;
<?php if( the_sub_field('popular') == 'Yes' ): ?>
Correct Answer
<?php elseif( the_sub_field('popular') == 'No' ): ?>
Wrong answer
?php endif; ?>
Yet it outputs as e.g. YesYes or NoNo, where I am I going wrong for it to output as the correct answer??
Thanks
the_sub_field() echos the value of the field. The result of an echo is always true. You need to use get_sub_field()
<?php if( get_sub_field('popular') == 'Yes' ): ?>
Correct Answer
<?php elseif( get_sub_field('popular') == 'No' ): ?>
Wrong answer
?php endif; ?>
As always John you are fantastic!
As always it’s only one little thing wrong!! Grrr
Cheers! 🙂
The little things always slip by, especially when the human brain tends read what it expects instead of what’s actually there. Wouldn’t it be great if we developers could turn that off?