dadra
dadra

Reputation: 153

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.

Upvotes: 4

Views: 21974

Answers (1)

doublesharp
doublesharp

Reputation: 27609

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; ?>

Upvotes: 11

Related Questions