I have a select field with a list of choices like “value : Label” and the data format set to “Value”.
How can I get the values of the choices?
My code is:
<?php
$uf_field = get_field_object('field_5fff35040e0f4');
if($uf_field) :
echo '<select name="estado"><option value="" disabled selected>ESTADO</option>';
foreach($uf_field['choices'] as $uf ) :
echo '<option value="' . $uf['value'] . '">' . $uf . '</option>';
endforeach;
echo '</select>';
endif;
?>
But it is returning the first letter of the label. I allready tried to set the data format to label and also to “both” (then setting the $uf[‘value’][0], but it still doesn’t return the value).
<?php
$uf_field = get_field_object('field_5fff35040e0f4');
if($uf_field) :
echo '<select name="estado"><option value="" disabled selected>ESTADO</option>';
foreach($uf_field['choices'] as $value => $label) :
echo '<option value="' . $value . '">' . $label . '</option>';
endforeach;
echo '</select>';
endif;
?>