WP高级自定义字段 - 如果/ else语句,则为真/假字段

dad*_*dra 3 wordpress if-statement advanced-custom-fields

我正在使用ACF单选按钮字段根据勾选"是"或"否"切换代码显示.像这样:

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

    some stuff here

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

    some other stuff here

<?php endif; ?>
Run Code Online (Sandbox Code Playgroud)

但我真正喜欢的是使用True/False字段并在未选中时显示一些默认代码,并在选中时显示不同的代码.我只是不确定如何调整上面的代码来反映使用True/False字段.有任何想法吗?提前致谢.

dou*_*arp 8

由于只有两个值,您只需要检查"已检查"状态,即"是"值或您配置的任何值.

<?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; ?>
Run Code Online (Sandbox Code Playgroud)