Home › Forums › General Issues › [Checkbox] How to display all item as check uncheck › Reply To: [Checkbox] How to display all item as check uncheck
So the original answer was written before this was an option, in fact, the documentation here for the checkbox does not give what the array looks like and I’ve never used this option. The returned array looks something like this
Array
(
[0] => Array
(
[value] => 1
[label] => One
)
[1] => Array
(
[value] => 2
[label] => Two
)
[2] => Array
(
[value] => 3
[label] => Three
)
)
Given that you need to loop through both the choices and the values
$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,': ';
foreach ($values as $value) {
if ($value['value'] == $choice_value) {
echo 'checked';
}
}// end foreach $values
} // 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.