Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WP Advanced Custom Fields - True/False field if/else statement

I'm using an ACF Radio Button field to toggle the display of code based on ticking "yes" or "no". Like this:

<?php if (get_field('toggle') == 'no'): ?>

    some stuff here

<?php elseif(get_field('toggle') == 'yes'): ?>

    some other stuff here

<?php endif; ?>

But what I'd really like is to use the True/False field and have it display some default code when unchecked, and different code when checked. I'm just not sure how to adapt the code above to reflect that use of the True/False field. Any ideas? Thanks in advance.

like image 951
dadra Avatar asked Oct 29 '25 15:10

dadra


1 Answers

Since there are only two values you only need to check for the "checked" state, which is a value of "yes" or whatever you have configured it to be.

<?php if ( 'yes' == get_field('toggle') ): ?>
    The box is checked (set to "yes")
<?php else: ?>
    The box is NOT checked (either false or "no")
<?php endif; ?>
like image 134
doublesharp Avatar answered Oct 31 '25 13:10

doublesharp