Basic usage:
Use the following code to create checkbox field:
1 2 3 4 5 6 7 8 9 10 11 12 13 |
$xbox->add_field(array( 'id' => 'custom-checkbox', 'name' => __( 'Custom checkbox', 'textdomain' ), 'type' => 'checkbox', 'default' => array('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-checkbox', 'name' => __( 'Custom checkbox', 'textdomain' ), 'type' => 'checkbox', 'default' => array('$all$'),// Add $all$ if you need to activate all by default. ;) 'items' => array( 'option1' => 'Option 1', 'option2' => 'Option 2', 'option3' => 'Option 3', ), 'options' => array( 'in_line' => false, //Default: true ) )); |
Result:
Getting saved value:
1 2 3 4 5 6 7 8 9 10 11 12 13 |
$xbox = Xbox::get( 'metabox-id' ); $value = $xbox->get_field_value( 'custom-checkbox' ); print_r($value); //Return: array(3) { [0]=> string(7) "option1" [1]=> string(7) "option2" [2]=> string(7) "option3" } |