Home Forums General Issues How to display unchecked choices


How to display unchecked choices

  • Hello, I have a field where I want to display both checked and unchecked choices. I have tried many code examples I have found but none of them work. I have managed to display the checked values, but how can I make it show the unchecked values aswell? Here the code I am currently using:

    <?php while( have_rows('car_info', 51) ): the_row();
    $values = get_sub_field('car_what_covered');
    if($values) {
    foreach($values as $value) { ?>
    <div class="point-row"><?php echo $value; ?> (checked)</div>
    <?php }
    } endwhile; ?>

    Heres also a image of my field setup if it helps.


      while (have_rows('car_info', 51)) {
        $values = get_sub_field('car_what_covered');
        $field = get_field_object('car_what_covered');
        $choices = $field['choices'];
        foreach ($choices as $choice) {
            <div class="point-row"><?php echo $choice; ?>
                if ($values && in_array($choice, $values)) {
                  echo ' (checked)';
                } else {
                  echo ' (not checked)';
        } // end foreach choice
      } // end while have_rows
Viewing 2 posts - 1 through 2 (of 2 total)

The topic ‘How to display unchecked choices’ is closed to new replies.