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
$values = get_field(‘family_amenties’);
$field = get_field_object(‘family_amenties’);
$choices = $field[‘choices’];
foreach($choices as $choice_value => $choice_label) :
foreach ( $values as $value ) :
if( $value[‘value’] == $choice_value ) :
$class = ‘ class=”checked”‘;
$class = ”;
echo ‘<li’ . $class . ‘>’ . $choice_label . ‘‘;
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.
$field = get_field_object('family_amenties');
$values = $field['value'];
if( $values ): ?>
<?php foreach( $values as $value ): ?>
<li><?php echo $field['choices'][ $value ]; ?></li>
<?php endforeach; ?>
<?php endif; ?>