Skip to content

Instantly share code, notes, and snippets.

@danielvonmitschke
Created July 10, 2019 09:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save danielvonmitschke/8bc0fe942ef3df26db5f571cb2bd69ac to your computer and use it in GitHub Desktop.
Save danielvonmitschke/8bc0fe942ef3df26db5f571cb2bd69ac to your computer and use it in GitHub Desktop.
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