Single boolean checkbox.
If you want to add a list of checkboxes, see Checkboxes.
-
Example 1: Basic Checkbox
add_action( 'fm_post_post', function() { $fm = new Fieldmanager_Checkbox( array( 'name' => 'demo-field', 'label' => 'Checkbox Label', ) ); $fm->add_meta_box( 'Basic Checkbox', array( 'post' ) ); } );
-
Example 2: Setting Checked/Unchecked Values
By default, the checked and unchecked values are boolean
true
andfalse
(which WordPress stores in the database as the string1
when checked, or an empty string when unchecked). In this example, we change these values to "yes" and "no" respectively.add_action( 'fm_post_post', function() { $fm = new Fieldmanager_Checkbox( array( 'name' => 'demo-field', 'label' => 'Sample Checkbox', 'checked_value' => 'yes', 'unchecked_value' => 'no', ) ); $fm->add_meta_box( 'Custom Checkbox Values', array( 'post' ) ); } );