Fields / Checkbox

Read More: Fieldmanager_Checkbox

Single boolean checkbox.

If you want to add a list of checkboxes, see Checkboxes.

  1. 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' ) );
    } );
  2. Example 2: Setting Checked/Unchecked Values

    By default, the checked and unchecked values are boolean true and false (which WordPress stores in the database as the string 1 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' ) );
    } );