Simple Fields
Value of Radio Buttons (8 posts)

  1. jvinch
    Posted 5 years ago #


    Calling the value of a simple field with:

    <?php $selected_value = get_post_meta(get_the_id(), "_simple_fields_fieldGroupID_1_fieldID_7_numInSet_0", true);
    echo "$selected_value";

    These values are set using radio buttons - but the value returned isn't the actually value but rather


    This is also the value in the WordPress database - but what am I missing here?


  2. Pär Thernström
    Plugin Author

    Posted 5 years ago #

    Hm.. good question. I can not actually for sure remember right why I do it like that! But I do think that I maybe thought that it should return the "index" of the selected radio button, instead of the entered value. This way you could change the values (correct spellings or in other ways update the text on a radio button) without the need to change you templates.

    Does that make sense? :)

  3. gfors
    Posted 5 years ago #

    Ok, so how would one show the actual value that is entered in the field?

    For example I have made a dropdown list with Simple Fields, and I actually want to show the value that I enter for each drop-down option, and not "dropdown_num_4".

    The documentation on eskapism.se even shows that It's supposed to show the value (your example with the color box, method 3, at http://eskapism.se/code-playground/simple-fields/tutorial-part-2/).

    The example on your page wouldn't output "green", it would say something like "dropdown_num_2".

    Thanks for an awesome plugin, and please straighten this issue out. Otherwise it's excellent!

    EDIT: Managed to change the plugin myself to save the value and not the index to the post_meta in DB. But I think this should be the default behavior.

  4. akshadap
    Posted 4 years ago #


    I am facing the same problem, I see "dropdown_num_3" instead of actual value. I searched in code also but do not understood :P

    Can anyone help?


  5. shua
    Posted 4 years ago #

    can you share the edit?


  6. shua
    Posted 4 years ago #

    Found it - and for all you people out there that would also like this plugin to work as expected...

    line 436

    echo "<option $selected value='$one_option_internal_name'>$dropdown_value_esc</option>";


    echo "<option $selected value='$dropdown_value_esc'>$dropdown_value_esc</option>";

    good luck!

  7. Pierre RASO
    Posted 4 years ago #

    Great tip but :

    • you could do the same for radio buttons
      change in functions_post.php, line 418:
      echo "<input $selected name='$field_name' id='$radio_field_unique_id' type='radio' value='$one_radio_option_key' />";
      to :
      echo "<input $selected name='$field_name' id='$radio_field_unique_id' type='radio' value='".esc_html($one_radio_option_val["value"])."' />";
    • I think you will have problems with simple fields front-end functions (simple_fields_get_post_value and simple_fields_get_post_group_values) which use special processing to retrieve stored values for dropdown and radio buttons.
      for this change in functions_post.php, lines 792 and 862 (simple fields 0.3.9) or lines 779 and 849 (simple fields 0.3.8) :
      $saved_values[$saved_i] = $one_field[$get_value_key][$saved_values[$saved_i]]["value"];
      if ($one_field[$get_value_key][$saved_values[$saved_i]]["value"]) {$saved_values[$saved_i] = $one_field[$get_value_key][$saved_values[$saved_i]]["value"];}

    This works fine for me with 0.3.8

  8. Pierre RASO
    Posted 4 years ago #

    @shua somthing is missing in your code (and mine for radio buttons) : when editing again, selected velue does not appear as selected. Default value appears as selected instead
    So, I had to change in functions_post.php, line 433
    if ($use_defaults == false && $saved_value == $one_option_internal_name) {
    if ($use_defaults == false && $saved_value == $dropdown_value_esc) {

    and change line 414 :
    if ($saved_value == $one_radio_option_key) { $selected = " checked='checked' "; }
    if ($saved_value == esc_html($one_radio_option_val["value"])) { $selected = " checked='checked' "; }

Topic Closed

This topic has been closed to new replies.

About this Plugin

  • Simple Fields
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic