Repeatable field groups allow you to repeat a group of 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.
For example, you might have a custom post type for “Houses”. Each house will have multiple rooms and each room will have its own separate information, with fields for the particular room type, flooring, and size. Using repeatable field groups allows you to achieve this structure and add as many rooms to any house that you post on your site.
Repeatable field groups can be added to any standard group of fields. This includes post, user and term field groups.
Follow these steps to add a repeatable field group:
- Go to the Toolset -> Custom Fields page and click on Add New custom fields group.
- Select the type of the field group you want to create: post, user, or term fields.
- Name your main field group and save it.
- 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.
- Click on the Add New Repeatable Group button, name the repeatable group, and start adding fields to it.
You can nest repeatable groups inside other repeatable groups without any limit to the number of nesting levels. To nest a group, first create a new repeatable field group and then drag-and-drop it inside another repeatable group.
Next, when you edit the related posts, you can add as many instances of the repeatable fields as you need. You can also reorder and delete them, if required.
If you wish to display a repeatable fields group, you need to use a View. Basically, a View allows you to list any kind of content on your site. The View will go through all the items in the repeating field group. You can instruct it how to display each item and the View will produce the required list.
Repeatable field groups are related to a specific post type. In our example, we added them to houses. This means that you need to add a View that lists the repeatable fields to a template for single posts of that particular type (i.e. houses).
Use the following steps to display repeatable field groups.
- Create a View that will list the repeatable field group.
- In the Content Selection section, select your repeatable field group, under the Repeatable field groups sub-section.
- In the Query Filter section, add a new Post relationship filter. Select the slug of your repeatable field group and the Post where this View is shown option.
- Go to the Loop Output Editor section and use the Loop Wizard button to select post fields you want to display.
- Edit the template for the single posts (i.e. for houses). Click on the Fields and Views button and insert the View that you created into this template as shown in the image below.
And that’s it! Now, when you visit your custom posts on the front-end, you will also see the list of repeatable fields.
Repeatable field groups that are nested inside other ones are also displayed using Views. The only difference is that you need to insert the View that displays nested group into the one that displays the main group. Basically, it implies using nested Views.
For example, let’s say that our repeatable group for “Rooms” features another repeatable group for “Room Equipment”. In this case, we need to create another View for listing “Room Equipment,” and insert it (nest it) into the View we created for displaying the main repeatable group for “Rooms”.
Go to the Getting Started support page, leave a comment and we will reply to you.