• Anonymous User 303747

    (@anonymized-303747)


    Hi,

    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

    radiobutton_num_2

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

    https://www.ads-software.com/extend/plugins/simple-fields/

Viewing 7 replies - 1 through 7 (of 7 total)
  • Plugin Contributor eskapism

    (@eskapism)

    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? ??

    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 https://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.

    Hello,

    I am facing the same problem, I see “dropdown_num_3” instead of actual value. I searched in code also but do not understood ??

    Can anyone help?

    Thanks

    gfors,
    can you share the edit?

    cheers,
    shua

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

    functions_post.php
    line 436
    change

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

    to

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

    good luck!

    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"];
      to
      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

    @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) {
    to
    if ($use_defaults == false && $saved_value == $dropdown_value_esc) {

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

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘[Plugin: Simple Fields] Value of Radio Buttons’ is closed to new replies.