Basic usage:
Use the following code to create select field:
1 2 3 4 5 6 7 8 9 10 11 12 |
$xbox->add_field( array( 'id' => 'custom-select', 'name' => __( 'Select', 'textdomain' ), 'type' => 'select', 'default' => 'male', 'items' => array( 'male' => 'Male', 'female' => 'Female', ), )); |
Result:
Advanced usage, with available options:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
$xbox->add_field( array( 'id' => 'text-align', 'name' => __( 'Text align', 'textdomain' ), 'type' => 'select', 'default' => 'initial', 'items' => array( 'left' => 'Left', 'right' => 'Right', 'center' => 'Center', 'justify' => 'Justify', 'initial' => 'Initial', 'inherit' => 'Inherit', ), 'grid' => '3-of-8', 'options' => array( 'sort' => 'asc',//Sort the list of items. 'asc' or 'desc'. Default: false 'search' => true, //Displays an input to search items. Default: false 'multiple' => true, //You can choose several options. Default: false 'max_selections' => 2//Maximum number of items to choose. If multiple is true. Default: 1 ) )); |
Result:
Getting saved value:
1 2 3 4 5 6 7 8 |
$xbox = Xbox::get( 'metabox-id' ); $value = $xbox->get_field_value( 'custom-select' ); var_dump($value); //Return: string(4) "male" |