
Hello, I got some troubles on an existing code I have to upgrade.
Today, only one value can be set for a select custom field in the back-office and this is the code I have to show on front-end
<?php
if (get_field('display_voyage_type_moto') == true) :
$field = get_field_object('voyage_type_moto');
?>
<li>
<p class="title">Type de moto</p>
<span><i class="icon-moto-route <?php if (get_field('voyage_type_moto') == 'trip_moto_route') {echo 'active';} ?>"></i><em><?php echo $field['choices']['trip_moto_route']; ?></em></span>
<span><i class="icon-moto-terrain <?php if (get_field('voyage_type_moto') == 'trip_moto_terrain') {echo 'active';} ?>"></i><em><?php echo $field['choices']['trip_moto_terrain']; ?></em></span>
<span><i class="icon-moto-trail <?php if (get_field('voyage_type_moto') == 'trip_moto_trail') {echo 'active';} ?>"></i><em><?php echo $field['choices']['trip_moto_trail']; ?></em></span>
<span><i class="icon-moto-harley <?php if (get_field('voyage_type_moto') == 'trip_moto_harley') {echo 'active';} ?>"></i><em><?php echo $field['choices']['trip_moto_harley']; ?></em></span>
</li>
<?php endif; ?>
If I change the option for having multiple choices on the select, the code doesn’t work anymore, no more class .active is working.
How can I change this code in order to have all the values selected in back office as class .active in front ?
Thanks for your time, have a good day
When you have a select field set to allow multiple selections then it will return an array here
get_field('voyage_type_moto')
so you need to check if the value is in the array
$value = get_field('voyage_type_moto');
....
<?php if (in_array('trip_moto_route', $value)) {
....
`