The repeater field is useful for creating a list of items based on the same fields, for example listing the members of a team.
The repeater field lets you list items without turning them into pages, as would be the case with a Custom Post Type. It is therefore better suited for cases where the listed items do not need a dedicated URL.
This field is only available in the pro versions of Modern Fields.
Configuration
Go to Modern Fields > Field groups and create a new group. Insert the Repeater block.
The repeater field acts as a container, allowing you to insert fields inside it.
You can arrange the inner fields by using columns, rows and grid inside the repeater.
Several options are available for the repeater field:
| Effect | |
|---|---|
| “Add button” label | Define the label of the bottom button. Eg: add a team member. |
| Min rows | The minimum number of items expected. |
| Max rows | The maximum number of items expected. |
| Row styles | Define the background and border color of the repeater container. |
Use the repeater field
The repeater field is easy to use: click on the “Add button” to add a new row of fields. You can delete a row by clicking the trash bin icon on the right of the row.
You can also reorder items by dragging them by the handle on the left of the row.
Display values with PHP
For now, you’ll need to use PHP to display the repeater values. We plan to add a dedicated blocks in the near future.
The easiest way is to first register a custom block with Modern Fields.
In the template, get the field value and loop through it:
You can also display a repeater values in a standard PHP context:
In this example, get_field() is the shorthand function you can enable in Modern Fields settings.