Support

Account

Home Forums Front-end Issues Get field choices values

Helping

Get field choices values

  • 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;
    ?>
    
Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.