Skip to content
Justin Sternberg edited this page May 13, 2019 · 3 revisions

If you didn't know, the example-functions.php contains examples for how to use CMB2 in many different contexts, including registering fields for many different object types:

Comment-edit page

Add fields to the comment-edit page:

add_action( 'cmb2_admin_init', 'yourprefix_register_comment_metabox' );
/**
 * Hook in and register a metabox for the admin comment edit page.
 */
function yourprefix_register_comment_metabox() {

	/**
	 * Sample metabox to demonstrate each field type included
	 */
	$cmb = new_cmb2_box( array(
		'id'           => 'yourprefix_comment_metabox',
		'title'        => 'Test Metabox',
		'object_types' => array( 'comment' ),
	) );

	$cmb->add_field( array(
		'name' => 'Test Text Small',
		'desc' => 'field description (optional)',
		'id'   => 'yourprefix_comment_textsmall',
		'type' => 'text_small',
		'column' => array(
			'position' => 2,
			'name' => 'CMB2 Custom Column',
		),
	) );

	$cmb->add_field( array(
		'name'    => 'Test Color Picker',
		'desc'    => 'field description (optional)',
		'id'      => 'yourprefix_comment_colorpicker',
		'type'    => 'colorpicker',
		'default' => '#ffffff',
		'column' => array(
			'position' => 2,
		),

	) );
}

Documentation:

  1. Home

  2. Installation
    Installation instructions for various environments

  3. Basic Usage
    Get up and running

  4. Advanced Usage
    Not for the faint of heart

  5. Field Types
    Breakdown of field types

  6. Examples
    Examples for registering fields

  7. Field Parameters
    Breakdown of common field parameters

  8. Display Options
    Limit display of boxes

  9. Box Properties
    Breakdown of box properties

  10. Troubleshooting
    Common issues & how to deal with them

  11. Notable Changes in CMB2 (from original CMB)
    CMB2 — a complete re-write

  12. Tips & Tricks
    10x your CMB2 skills

  13. REST API
    CMB2 data through WordPress REST API

  14. Javascript API
    Work with CMB2 JS events & hooks

Advanced tutorials:

External Resources:

Clone this wiki locally