Repeatable field groups allow you to repeat a group of custom fields as many times as needed. Further, it enables you to nest repeatable groups inside other such groups. Toolset also allows you to easily display repeatable field groups on the front-end.

Example

In our example, we’re building a directory site about gyms. Each gym has a section about opening hours. Because opening hours are different for each gym we can add them as a repeatable group of custom fields.

In our repeatable group, we can repeat days and each day can have a field for the day’s name and day’s opening hours.

Repeatable field groups when editing a post
Repeatable field groups when editing a post

How-to steps

Creating Repeatable Field Groups

Repeatable field groups can be added to any group of fields used for posts.

Follow these steps to add a repeatable field group:

  1. Go to the Toolset Custom Fields page and click on  Add New custom fields group.
  2. Select to create a post field group.
  3. Name your main field group and save it.
  4. To be able to insert a repeatable group of fields, your main group needs to be assigned to a single post type. Click on the Edit button in the Where to include this Field Group section and select one post type.
  5. Click on the Add New Repeatable Group button, name the repeatable group, and start adding fields to it.

Repeatable Field Group
Repeatable Field Group

Next, when you edit the related posts, you can add as many instances of repeatable fields as you need. You can also reorder and delete them.

Displaying Repeatable Field Groups

To display a repeatable field group, you need to use a View. The View will go through all the items in the repeating field group. You can set how it displays each item and the View will produce the required list.

To create a View, you need to be familiar with the WordPress Block Editor. If you’re not, take a few minutes to learn how to use the Block Editor.

Repeatable field groups are related to a specific post type. In our example, we added them to gyms. This means that you need to edit a template for displaying single posts of that post type and add a View that lists the repeatable fields of that particular type (i.e. gyms).

Use the following steps to display repeatable field groups.

  1. Edit the Content Template for single posts of the related post type.
  2. Insert a View block, give it a name, and select the design options.
  3. In the third step of the View creation wizard, you select the content that this View will display. Select your repeatable field group, under the Repeatable field groups sub-section.

    Selecting the repeatable field group in the View creation wizard
    Selecting the repeatable field group in the View creation wizard

  4. In the Block Editor, click to select the main View block you just created. This is because when you create a View block, its inner View Loop block is selected by default.
  5. In the right sidebar, expand the Query Filter section and click the Add a filter button.

    Add a filter
    Add a filter

  6. In the dialog that appears, select the Post relationship or repeatable field groups owner option.
  7. In the right sidebar, use the Select items dropdown to select your repeatable field group and click the Save button.

    Select repeatable field group
    Select repeatable field group

You have now set up the View to display the repeatable field groups of your posts. All that is left to do is to add different blocks to output the fields from your repeatable groups. In our example, we added two Single Field blocks. One to display the custom field for the name of the day and another to display a custom field for the opening hours.

And that’s it! Now, when you visit your custom posts on the front-end, you will also see the list of repeatable fields.

Gym opening hours displayed on the front-end using a repeatable field group
Gym opening hours displayed on the front-end using a repeatable field group

Displaying Repeatable Field Groups in Custom Order

You can easily arrange the order of items in a repeatable field group by drag-and-dropping them. However, by default, the front-end output will not be in this order.

To list items in a custom order, select the main View block and in the right sidebar, expand the Ordering Settings section. In the Sort By dropdown, select the Field – toolset-post-sortorder option. Also, select the order to be Ascending.

Displaying the list of repeatable field groups in the custom order
Displaying the list of repeatable field groups in the custom order

What’s next?

Front-end Forms For Repeatable Field Groups

Need help?

If you run into any problems or need our advice, create a new support ticket and our team will be happy to assist you.