Skip to content

Instantly share code, notes, and snippets.

@rilwis
Created May 17, 2016 01:34
Show Gist options
  • Save rilwis/296d25f56f8590aee2a0bf7cfcb4f872 to your computer and use it in GitHub Desktop.
Save rilwis/296d25f56f8590aee2a0bf7cfcb4f872 to your computer and use it in GitHub Desktop.
Nested group demo
<?php
add_filter( 'rwmb_meta_boxes', 'nested_groups_demo' );
function nested_groups_demo( $meta_boxes )
{
// Meta Box
$meta_boxes[] = array(
'title' => __( 'Books', 'rwmb' ),
'fields' => array(
array(
'id' => 'authors',
'name' => __( 'Authors', 'rwmb' ),
'type' => 'group', // Group type
'clone' => true,
// List of child fields
'fields' => array(
array(
'name' => __( 'Full Name', 'rwmb' ),
'id' => 'name',
'type' => 'group',
'fields' => array(
array(
'id' => 'first_name',
'name' => __( 'First Name', 'rwmb' ),
'type' => 'text',
),
array(
'id' => 'last_name',
'name' => __( 'Last Name', 'rwmb' ),
'type' => 'text',
),
),
),
array(
'name' => __( 'Phone', 'rwmb' ),
'id' => 'phone',
'type' => 'text',
'size' => 10,
),
array(
'name' => __( 'Email', 'rwmb' ),
'id' => 'email',
'type' => 'email',
'size' => 15,
),
),
),
),
);
return $meta_boxes;
}
<?php
$meta_boxes[] = array(
'title' => 'Multi-level nested groups',
'fields' => array(
array(
'id' => 'group4',
'type' => 'group',
'clone' => true,
'fields' => array(
// Normal field (cloned)
array(
'name' => 'Text',
'id' => 'text4',
'type' => 'text',
'clone' => true,
),
// Nested group level 2
array(
'name' => 'Sub group',
'id' => 'group2',
'type' => 'group',
'clone' => true,
'fields' => array(
// Normal field (cloned)
array(
'name' => 'Sub text',
'id' => 'text4',
'type' => 'text',
'clone' => true,
),
),
),
),
),
),
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment