-
Notifications
You must be signed in to change notification settings - Fork 124
Group field
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.
- id (string) (required)
- name (string) (required) Field display name. Used as field group title.
- type 'group' (string) (required)
- 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,
array(
'id' => 'example-group',
'name' => 'A Group',
'type' => 'group',
'fields' => $fields // An array of fields.
),
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.
- Setup/Install Custom Meta Boxes
- Creating a custom meta box
- Displaying Field Data
- Optional Generic Field Args
- Repeatable Fields
General
- Text Field
- Small Text Field
- Number Field
- URL Field
- Textarea Field
- Code Field
- Select Field
- Checkbox Input Field
- Radio Input Field
Date & Time
WordPress
Media
Utilities