Skip to content
Barry Ceelen edited this page Jan 11, 2016 · 8 revisions

A repeatable field allows you to add multiple values for a single field.

To create a repeatable field, add 'repeatable' => true to the field args.

Any field can be made repeatable.

Repeatable fields are stored as separate meta entries using the same meta key.

When using repeatable you can also set repeatable_max to restrict the number of repeatable fields that can be created.

Args

Required Args

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

Args Specific To Repeatable Fields

  • repeatable (bool) (required)
  • repeatable_max (int) (optional) Restrict number of fields to repeat.
  • string-repeat-field (string) (optional) Text for add button.
  • string-delete-field (string) (optional) Text for delete button.

Optional Generic Args

See Optional Generic Args

Example Usage

array(
	'id'                  => 'example-field-text',
	'name'                => 'A simple text input',
	'type'                => 'text',
	'repeatable'          => true,
	'repeatable_max'      => 5,

Using repeatable field data in your theme

// Note that the 3rd param is false to retrieve all meta entries with the same key (This is false by default)
$field_data = get_post_meta( get_the_id(), 'example_repeatable_field', false );

foreach ( $field_data as $single_field )
    echo $single_field;