Set Selected by default in Radio box

Support General Set Selected by default in Radio box

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #4415
    MD3MD3
    Participant

    I have this code

    array(
    				'id'      => $prefix.'featured_product',
    				'name'    => 'Featured Product',
    				'type'    => 'radio',
    				'options' => array(
    					'yes' => 'Yes',
    					'no'  => 'No',
    				),
    			),

    I want to make "No" as selected by default.. how to do it?

    #4431
    Anh TranAnh Tran
    Keymaster

    Just add 'std' => 'no' to the field 😉

    #14722
    Nuno CruzNuno Cruz
    Participant

    I did not understand
    I have an input of type radio:
    Man (x) Woman (_)
    How do I do this?

    #14724
    Anh TranAnh Tran
    Keymaster

    Hi Nuno,

    You just need to define the field like this:

    array(
      'id' => 'field_id',
      'name' => 'Gender',
      'options' => array(
        'm' => 'Man',
        'w' => 'Woman',
      ),
      'std' => 'm',
    )
    #14726
    Nuno CruzNuno Cruz
    Participant

    Not work 🙁

    array (
        'id' => 'sexo',
        'name' => 'Sexo',
        'type' => 'radio',
        'std' => 'Homem',
        'options' => array(
            'Homem' => 'Homem',
            'Mulher' => 'Mulher',
        ),
        'required' => 1,
    ),
    #14746
    Anh TranAnh Tran
    Keymaster

    Probably, you're on an old post or your meta box has already been saved. See this for more details:

    https://docs.metabox.io/field-settings/#default-value

Viewing 6 posts - 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.