Custom Fields
Re-Envisioned
Support General Select Custom Fields not saving selection

  • Creator
    Topic
  • #28228
    Resolved harryb
    Participant

    Hi - my Select Custom Fields don't seem to show the saved the selection when you return to edit the page.

    When editing a page I can make a selection and then click "Update" and the selection shows correctly in the front end. However, when I go back to edit the page later, the field in the select option just shows whatever is at the top of the select options rather than what was saved previously.

    This means that if I make an edit to the page I also have to remember to re-select the correct field from the Select Custom Field as well as making whatever other edit I was there for.

Viewing 9 replies - 1 through 9 (of 9 total)
  • Author
    Replies
  • #28233
    Long Nguyen
    Moderator

    Hi Harry,

    Can you please share the code that creates the custom fields? I will check it on my end.

    #28236
    harryb
    Participant

    Hi Long - many thanks.

    In fact, it does noes not overwrite with the default if you update the page but whatever is at the top of the select list is what shows in the field - even if you have selected something further down the list and saved previously. This means if you go to edit the page, you can't be sure the correct value has been selected from the Select field or not.

    These are just text fields created using MB AIO so I'm not sure what code I can send you? Please let me know and I'll send it over.

    #28239
    Long Nguyen
    Moderator

    Hi Harry,

    You can generate the code by clicking on the button Get PHP Code in the Builder https://docs.metabox.io/extensions/meta-box-builder/#getting-php-code

    #28270
    harryb
    Participant

    Hi Long - so here's the php for the select fields (personal names removed). As I said, the problem is that when you go back into the page to edit, the field does not show what was saved previously even though the correct information shows on the front end.

     [
                    'name'     => __( 'Host', 'your-text-domain' ),
                    'id'       => $prefix . 'event_host',
                    'type'     => 'select',
                    'options'  => [
                        'TBC'                        => __( 'TBC', 'your-text-domain' ),
                        'Long Event - Several Hosts' => __( 'Long Event - Several Hosts', 'your-text-domain' ),
                        'XXX1'                       => __( 'XXX1', 'your-text-domain' ),
                        'XXX2'                       => __( 'XXX2', 'your-text-domain' ),
                        'XXX3'                       => __( 'XXX3', 'your-text-domain' ),
                        'XXX4'                       => __( 'XXX4', 'your-text-domain' ),
                        'XXX5'                       => __( 'XXX5', 'your-text-domain' ),
                        'XXX6'                       => __( 'XXX6', 'your-text-domain' ),
                        'XXX7'                       => __( 'XXX7', 'your-text-domain' ),
                        'XXX8'                       => __( 'XXX8', 'your-text-domain' ),
                     ],
                    'required' => true,
                ],
    #28275
    Long Nguyen
    Moderator

    Hi Harry,

    There is nothing wrong with your code. It might come from another issue. Please follow the step Debugging Information to troubleshoot the issue https://metabox.io/support/topic/how-to-create-a-new-topic/

    If it does not work, please share your site credentials via this form https://metabox.io/contact/. I will help you to check it.

    #28799
    Long Nguyen
    Moderator

    Hi Harry,

    I've received your site info in the ticket system and got the issue.

    The choices of the select field in the Builder should be value: Label and the value should not have & character. You can use the space instead of it. Please re-check the field Event Host and confirm it works.

    #28802
    harryb
    Participant

    That's great - many thanks Long. So just to check, if the select choices should be: "Bob Smith", "Mary Smith" and "Bob and Mary Smith", it would be entered in the builder as:

    Bob Smith: Bob Smith
    Mary Smith: Mary Smith
    Bob and Mary Smith: Bob and Mary Smith

    Thanks,

    Harry

    #28803
    harryb
    Participant

    And just checking this would be ok also?

    Bob Smith: Bob Smith
    Mary Smith: Mary Smith
    Bob and Mary Smith: Bob & Mary Smith

    #28815
    Long Nguyen
    Moderator

    Yes, it would be ok. Just remove & character from the value.

    Bob Smith: Bob Smith
    Mary Smith: Mary Smith
    Bob and Mary Smith: Bob & Mary Smith
Viewing 9 replies - 1 through 9 (of 9 total)
  • You must be logged in to reply to this topic.