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
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.