Custom Fields
Re-Envisioned
Support General Is `std` not support for select/select_advanced fields?

  • Creator
    Topic
  • #19444
    Resolved ComSi
    Participant

    I’m trying to get a drop down menu pre-filled with a default value, but it looks like both the select and select_advanced field types ignore this common setting?

    Example code below is based on the example on the docs:
    https://docs.metabox.io/fields/select-advanced/

    array(
        'name'        => 'Select Advanced',
        'id'          => 'select_advanced',
        'type'        => 'select_advanced',
        'placeholder' => 'Select an Item',
        'options'     => array(
            'java'       => 'Java',
            'javascript' => 'JavaScript',
            'php'        => 'PHP',
            'csharp'     => 'C#',
            'objectivec' => 'Objective-C',
            'kotlin'     => 'Kotlin',
            'swift'      => 'Swift',
        ),
        // This doesn't seem to work
        'std' => 'php'
    )

    Tested this in v5.2.10 (via composer).

    How can I set the default option of a select element?

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

    Hi there,

    The default option std for the field select or select_advanced still works as well. You can check with my sample code https://pastebin.com/AhgyVKhw generated by Online Generator and see my short screen record.

    Please check it again and let me know how it goes.

    #19495
    ComSi
    Participant

    Hi,

    Okay, I can see the misunderstanding now!
    The option is only used set when the post is created the very first time. After it has been saved once, the std option will be ignored.
    I thought it would only be ignore when that specific option has been saved once.

    I was creating a page and adding meta boxes one after another, while saving the post in between. Then when I added the select_advanced with the std option set, while the post had been saved before. In this case it is ignored.

    That took me quite a while to understand correctly.

Viewing 2 replies - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.
grid gear info copy caret-up caret-down trash