Basic usage:
Use the following code to create radio field:
1 2 3 4 5 6 7 8 9 10 11 12 13 |
$xbox->add_field(array( 'id' => 'custom-radio', 'name' => __( 'Custom radio', 'textdomain' ), 'type' => 'radio', 'default' => 'option2', 'items' => array( 'option1' => 'Option 1', 'option2' => 'Option 2', 'option3' => 'Option 3', ), )); |
Result:
Advanced usage, with available options:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
$xbox->add_field(array( 'id' => 'custom-radio', 'name' => __( 'Custom radio', 'textdomain' ), 'type' => 'radio', 'default' => 'option2', 'items' => array( 'option1' => 'Option 1', 'option2' => 'Option 2', 'option3' => 'Option 3', ), 'options' => array( 'in_line' => false, ) )); |
Result:
Getting saved value:
1 2 3 4 5 6 7 8 |
$xbox = Xbox::get( 'metabox-id' ); $value = $xbox->get_field_value( 'custom-radio' ); var_dump($value); //Return string(7) "option2" |