Skip to content

Instantly share code, notes, and snippets.

@Mamaduka
Created April 14, 2015 13:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save Mamaduka/f97dd20f5c79b18259b4 to your computer and use it in GitHub Desktop.
Save Mamaduka/f97dd20f5c79b18259b4 to your computer and use it in GitHub Desktop.
<?php
/**
* Register Team Members metabox as repeatable group fields.
*/
function maintainn_team_members_metabox() {
$prefix = '_maintainn_team_';
$cmb_group = new_cmb2_box( array(
'id' => $prefix . 'metabox',
'title' => __( 'Team Members', 'maintainn-demo' ),
'object_types' => array( 'page' ),
'show_on' => array( 'key' => 'page-template', 'value' => 'page-templates/full-width.php' ),
) );
$group_field_id = $cmb_group->add_field( array(
'id' => $prefix . 'meta',
'type' => 'group',
'description' => '',
'options' => array(
'group_title' => __( 'Member', 'maintainn-demo' ),
'add_button' => __( 'Add Another Member', 'maintainn-demo' ),
'remove_button' => __( 'Remove', 'maintainn-demo' ),
'sortable' => true
)
) );
$cmb_group->add_group_field( $group_field_id, array(
'name' => __( 'Fullname', 'maintainn-demo' ),
'id' => 'fullname',
'type' => 'text'
) );
$cmb_group->add_group_field( $group_field_id, array(
'name' => __( 'Position', 'maintainn-demo' ),
'id' => 'position',
'type' => 'text',
) );
$cmb_group->add_group_field( $group_field_id, array(
'name' => __( 'Photo', 'maintainn-demo' ),
'id' => 'photo',
'type' => 'file',
'options' => array(
'url' => false
)
) );
}
add_action( 'cmb2_init', 'maintainn_team_members_metabox' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment