Radio Field

Radio Field

IntroductionExampleUses

Introduction
The radio type field, part of the Settings API, renders a radio type input for each of the field choices.
Example
The radio button has a default_value of 「this is the label for choice2」 so the second choice will be selected. Because horizontal is set to true, the radio buttons will be displayed side-by-side instead of the default one per line.
1234567891011121314151617181920212223242526array(    'title'       => esc_html__( 'This is the title for Section 2', 'sometextdomain' ),    'description' => esc_html__( 'This is a description of the purpose of Section 2', 'sometextdomain' ),    'fields'      => array(        array(            'type'          => 'radio',            'name'          => 'myradio',            'label'         => esc_html__( 'this is the main label for the radio buttons', 'sometextdomain' ),            'default_value' => 'this is the label for choice2',            'horizontal'    => true,            'choices'       => array(                array(                    'name'    => 'choice1',                    'tooltip' => esc_html__( 'this is the tooltip for choice1', 'sometextdomain' ),                    'label'   => esc_html__( 'this is the label for choice1', 'sometextdomain' ),                    'value'   => 'this is the value for choice1'                ),                array(                    'name'    => 'choice2',                    'tooltip' => esc_html__( 'this is the tooltip for choice2', 'sometextdomain' ),                    'label'   => esc_html__( 'this is the label for choice2', 'sometextdomain' ),                ),            ),        ),    ),),
The code above will render the radio button field similar to the following:

Uses

settings_radio()
choices_have_icon()
get_choice_attributes()

發表回覆

您的電子郵箱地址不會被公開。 必填項已用 * 標註