Skip to content

Instantly share code, notes, and snippets.

@danielvonmitschke
Created Jul 10, 2019
Embed
What would you like to do?
add_action('cmb2_admin_init', function(){
$cmb = new_cmb2_box([
'id' => 'cmb_repeater_metabox',
'title' => 'Repeateable groups',
]);
$groups = $cmb->add_field([
'id' => 'cmb_groups',
'type' => 'group',
'options' => [
'group_title' => 'Entry {#}',
'add_button' => 'Add another entry',
'remove_button' => 'Remove entry',
'sortable' => true,
],
]);
$cmb->add_group_field(
$groups,
[
'id' => 'cmb_groups_image',
'name' => 'Image',
'type' => 'file',
]
);
$cmb->add_group_field(
$groups,
[
'id' => 'cmb_groups_text',
'name' => 'Text',
'type' => 'textarea_small'
]
);
});
add_filter('lg_cmb2_modals', function ($metaboxFormIds) {
$metaboxFormIds[] = 'cmb_repeater_metabox';
return $metaboxFormIds;
});
window["cmb_repeater_metabox_view"] = function (model) {
console.log(model);
return "REPEATABLE GROUPS";
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment