How to add repeatable field groups to your custom post types?
In our previous post, we outlined how post relationships make it easier to manage your website content. Now let’s look at another Toolset feature which will help you add some of that content quicker than ever before.
Repeatable field groups allow you to add a set of custom fields to a custom post type as many times as you want. Rather than wasting hours manually adding each individual custom field whenever you want to add new information, you can use this feature to create the set once and reuse them.
Let’s explore exactly how this can benefit you by using a repeatable field group to add more content to our real estate agent website. Remember that in the last post we added a post relationship to our “Agents” post type to display houses which our estate agent Tina was selling. Now we’ll add further content underneath our post relationship.
How repeatable field groups make it easier to add content
The repeatable field group is the perfect tool if we have lots of content which we need to add to a post in the same format.
Imagine that on our “Agents” posts we want to display their recommended reading to help people looking to buy a property. Each reading material will require the same custom fields – title, description, image etc. Of course, we could manually add each of these fields to our post whenever we want to add a new reading option but this takes time and we might miss a field out by accident. With repeatable field groups, we can create the template once and reuse it again and again.
Let’s add Tina’s reading recommendations with the help of a repeatable field group.
How to create your repeatable fields group
We can create our repeatable field group in minutes and without any coding. We first start as if we are adding normal custom fields by clicking Add custom fields within our “Agents” custom post type on the Toolset dashboard. From here, instead of adding new fields we click Add New Repeatable Group and name our custom field template. In this instance, we have called it “Recommended reading.” Now we add the custom fields that we want to be part of our repeatable field group. We have added five custom fields which you can see in the image below.
Once we save it, we can start adding Tina’s recommended reading on her edit post.
Adding content to a repeatable field group
Now we have created our repeatable field group we can easily add our content to each of our agent’s posts.
When we edit Tina’s post, we have a section called “Recommended reading” where we can add our material. As you can see below, all we need to do is click Add New Recommended reading and our template appears. From here, it is simply a case of filling in the fields just like you might fill in a form.
Having added our recommended reading, we can now consider how we will display our repeatable field group on the front-end.
Displaying our repeatable field group on the front-end
Remember here is how the back-end of our “Agents” post type looks:
1. We now need to create our View for the repeatable field group which will go at the bottom of each post. Once we select the “+” icon and choose where our View will we go, just need to select the Visual editor option to start creating it.
2. Now we select our “Recommended reading” repeatable field group and set the Query Filter. We set it to Filter by post relationship or repeatable fields group owner and to select any items which are in a relationship with The post where this View is shown. This ensures only Tina’s recommended reading is displayed on her post, for example.
3. The next step is to outline exactly how the results will look with the Loop Editor. Here, you can arrange whether or not you want to arrange the results in Bootstrap grid or other forms.
4. Finally, we need to decide exactly what fields we want to display by editing the Templates for this View and adding the custom fields from our repeatable field group.
5. Our View has now been created on the back-end and we can now see the results on the front-end.
As you’ve seen, what was once a prolonged and complex exercise is now simple thanks to Toolset’s repeatable field groups. You will now be able to add your content in less time than ever, allowing you to concentrate on other, more complicated areas of website building.
Let us know in the comments if you are using repeatable fields and if you would like to see more tutorials!