I tried to find a related topic on the acf site but that didn’t give me the right answer. Hopefully you guys can help me out.
I am building a custom website using ACF, everything is perfect and I managed to get almost everything exactly the way I want but with the checkboxes I can only display the checked ones but not the unchecked.
My idea is that the not checked ones would have a different “class” or “id” and I would display them with a different CSS style.
This is a list of features of the flats for rent, so things like: Internet, TV, etc. Much like airbnb’s website.
So the code. I managed to get this code to work:
<?php
$values = get_field('room_features');
if($values)
{
echo '<ul>';
foreach($values as $value)
{
echo '<li>' . $value . '</li>';
}
echo '</ul>';
}
?>
But this doesn’t display the unchecked ones, only checked.
I would appretiate any light on this 🙂
You can return an array of all data associated with a certain field using the get_field_object() function: http://www.advancedcustomfields.com/resources/get_field_object/
Here’s an example of the returned array on a checkbox field. Note the “choices” array.
You can use following code.
You will get the object which contains the all choices of checkbox.