Support

Account

Home Forums Front-end Issues Get field choices values

Helping

Get field choices values

    • jbmgil

    • January 19, 2021 at 3:52 am

    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.

We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.