My checkbox code is displaying all the fields. I only need it to display the active/selected fields. Everything else in the code is working fine and have managed to wrap some class css so it spreads over 3 columns.
// Current Code Used
<?php
$values = get_field(‘family_amenties’);
$field = get_field_object(‘family_amenties’);
$choices = $field[‘choices’];
?>
<?php
foreach($choices as $choice_value => $choice_label) :
foreach ( $values as $value ) :
if( $value[‘value’] == $choice_value ) :
$class = ‘ class=”checked”‘;
else :
$class = ”;
endif;
endforeach;
echo ‘<li’ . $class . ‘>’ . $choice_label . ‘‘;
endforeach;
?>
This reply has been marked as private.
Here is the fix if anyone is interested. This will output the selected checkbox items as a list.
<?php
// vars
$field = get_field_object('family_amenties');
$values = $field['value'];
// check
if( $values ): ?>
<ul>
<?php foreach( $values as $value ): ?>
<li><?php echo $field['choices'][ $value ]; ?></li>
<?php endforeach; ?>
</ul>
<?php endif; ?>