I have an ACF repeater field setup on a page and within the subfields I have a True/False checkbox. So far, if the box is checked, it will show the fields. If not then it will not.

However, the one thing I can't figure out is how to get it to check to see if nothing is checked, to only echo out something, but since it's in the while loop, it just keeps outputting for each sub field.

Here's my code:

      if( get_field('position') ) : while( has_sub_field('position') ) :
        $value = get_sub_field('active_position');
        $title = get_sub_field('position_name');
        <?php  if( $value == true ) : ?>
            <?php echo $title; ?>
        <?php else : ?>
            nothing available...

        <?php endif; ?>
      <?php endwhile; endif; ?>

I'm not sure how to get it so it checks to see if anything is "checked". If so, then display the results, but if nothing is checked then return something else only once.


From ACF Documentation:

* Conditional Statement

if( get_field('field_name') )
    echo "do something";
    echo "do something else";

So...to check if something is "NOT" checked is just the else of the above.

  • So, how would that work if the True/False checkbox is in the repeater? Is it possible to just query out the value of the True/False without needed to query the repeaters? – ultraloveninja Mar 9 '16 at 15:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.