Skip to content
Mike Selander edited this page Jul 24, 2016 · 15 revisions

A Group is a field that can contain other fields.

Pass an array of fields to the group. This is in the same format as when creating ungrouped fields.

Data for grouped fields are stored as serialized data on the group post meta entry.

Notes

  • Grouped field data cannot really be used when doing a WordPress meta query.
  • Nested groups are not supported.

Args

Required Args

  • id (string) (required)
  • name (string) (required) Field display name. Used as field group title.
  • type 'group' (string) (required)

Field Specific Args

  • fields (array) (required) Group fields. An array of fields.
  • string-repeat-field (string) Label for new group button,
  • string-delete-field (string) Label for delete group button,

Optional Generic Args

See Optional Generic Args

Example Usage ( single group )

array( 
	'id'   => 'example-group', 
	'name' => 'A Group', 
	'type' => 'group',
	'fields' => $fields // An array of fields. 
),

Using Grouped Field Data in a Theme

As noted above, All of the data for individual fields within a group is stored as a serialized array in post meta, using the group ID as the meta key.

To access this data, retrieve the meta data for the group, and use the grouped field ID to retrieve data from this. See the example below for more information:

$group_data = get_post_meta( get_the_id(), 'example-group', true );

	if ( ! empty( $group_data['group_field_1'] ) )
			echo esc_html( $group_data['group_field_1'] );

Note that as grouped field data is stored as a serialized array, it is not possible to use a single grouped field meta key to do a WordPress query.