Hey,
I m trying to display a different value if one condition is true. But I don’t know why that doesn’t work.
can you help me please ?
<?php
$values = get_field("lieu");
if ( $values == "maintenon" ) {
echo 'Chateau de Maintenon';
} elseif ($values == "compa") {
echo "Compa";
} elseif ($values == "archives") {
echo "Archives départementales";
} else {
echo "nothing";
}
?>
What kind of field is ‘lieu’
Checkbox fields return an array. The specifics of the array depend on what you have it set to return. Assuming that you are only returning the value then to check for a specific checkbox being checked:
if (in_array('maintenon', $values))
Thanks for this !
I use that and problem is solved !
<?php
// vars
$place = get_field('lieu');
// check
if( $place && in_array('maintenon', $place) ): ?>
<span class="label label-primary labellieu">Château de Maintenon</span>
<?php elseif( $place && in_array('archives', $place) ):?>
<span class="label label label-warning labellieu">Archives départementales</span>
<?php elseif( $place && in_array('compa', $place) ):?>
<span class="label label label-danger labellieu">Le Compa</span>
<?php elseif( $place && in_array('classe', $place) ):?>
<span class="label label-success labellieu">Dans la classe</span>
<?php endif; ?>