Support

Account

Home Forums Backend Issues (wp-admin) Opt group in select field works, but only returns value but no label Reply To: Opt group in select field works, but only returns value but no label

  • Hey James

    Thank you for helping me out. However I’m not sure I got everything right, we are talking about the selected choice’s valua/label pair and not the field’s label right?

    I tried to use the code in the example.

    If I use this for testing:

    $field = get_field_object('region');
      echo '<pre>';
      var_dump($field);
      echo '</pre>';
    

    I still get this:

    ["value"]=>
      array(2) {
        ["value"]=>
        string(6) "purple"
        ["label"]=>
        string(6) "purple"
      }

    So it seems to me it records the value twice in the database?

    edit:

    oh yeah, I forgot this, please keep in mind that my array got another level thanks to the opt group modification in the first post. So using the documentation’s example, my choices array looks like this for example:

    
    ["choices"]=>
      array(16) {
        ["UK - East"]=>
        array(6) {
          ["norfolk"]=>
          string(7) "Norfolk"
          ["suffolk"]=>
          string(7) "Suffolk"
          ["essex"]=>
          string(5) "Essex"
          ["hertfordshire"]=>
          string(13) "Hertfordshire"
          ["bedfordshire"]=>
          string(12) "Bedfordshire"
          ["cambridgeshire"]=>
          string(14) "Cambridgeshire"
        }

    So the “Display value and label” example won’t work here because it can’t find the actual label? So I guess this is a question of how to get the data here. Sorry I’m not a pro at PHP. Thank you in advance.