Support

Account

Home Forums General Issues [Checkbox] How to display all item as check uncheck Reply To: [Checkbox] How to display all item as check uncheck

  • If you are returning the value and the label in the field settings, it gets complicated. There isn’t an easy way to access the nested array values. We need to set a marker to see if we find it selected.

    
    $values = get_field('checkbox_field_name');
    $field = get_field_object('checkbox_field_name');
    $choices = $field['choices'];
    foreach ($choices as $choice_value => $choice_label) {
        echo $choice_label,': ';
        $found = false;
        foreach ($values as $value) {
          if ($value['value'] == $choice_value) {
            $found = true;
            echo 'checked';
          }
        } // end foreach $values
        if (!$found) {
          echo 'not ckecked';
        }
     } // end foreach $choices