Is `std` not support for select/select_advanced fields?

Support General Is `std` not support for select/select_advanced fields?Resolved

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #19444
    ComSiComSi
    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?

    #19453
    Long NguyenLong 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
    ComSiComSi
    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 3 posts - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.