Adding a repeater Accordion module

This article has been updated! Please check the addendum at the bottom.

Go to the addendum

Ever wondered if it was possible to add an ACF Repeater as the source for – for example – an Accordion module? Well.. you can. Here’s how:

There are a few things you need to do in preparation:

  1. Set up the a repeater-field with it’s subfields on the page, post or CPT
  2. Add a connections parameter to the Accordion
  3. Create a filter for the Toolbox Connector, specifically for the repeater

Step 1: set up the repeater-field

Add a Repeater field to your page, post or CPT. When you add the subfields, make sure they have a name that matches the fieldsnames used by the Accordion Module. In this case they should be ‘label’ and ‘content’. Don’t get confused by the “Label” for the Sub Fields, which could by whatever you want. make sure to save it.

Step 2: Add connections parameter

make sure you activated the ‘extra connection for the modules’ on your Toolbox Settings page in the dashboard. If you do, the connections option will be activated by the plugin.

Step 3: Create filter

This is the most interesting part of course. With just a tiny amount of code you can tell the plugin to return the subfields the way Beaver Builder expects it.

[pastacode lang=”php” manual=”%3C%3Fphp%0A%0Aadd_filter(%20’toolbox%2Fhelpers%2Fget_acf_field%2Ftype%3Drepeater’%20%20%20%20%20%20%20%2C%20%20%20%20%20%20%20’get_repeater_as_objects’%20%09%09%2C%2090%2C%205%20)%3B%0A%0A%2F**%0A%20*%20Get%20the%20repeater%20value%20as%20objects%2C%20not%20array%0A%20*%20%40param%20%20%5Btype%5D%20%24string%20%20%20%20%20%20%20%5Bdescription%5D%0A%20*%20%40param%20%20%5Btype%5D%20%24field_object%20%5Bdescription%5D%0A%20*%20%40param%20%20%5Btype%5D%20%24value%20%20%20%20%20%20%20%20%5Bdescription%5D%0A%20*%20%40param%20%20%5Btype%5D%20%24atts%20%20%20%20%20%20%20%20%20%5Bdescription%5D%0A%20*%20%40param%20%20%5Btype%5D%20%24postid%20%20%20%20%20%20%20%5Bdescription%5D%0A%20*%20%40return%20%5Btype%5D%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%5Bdescription%5D%0A%20*%2F%0Afunction%20get_repeater_as_objects(%20%24string%20%2C%20%24field_object%20%2C%20%24value%20%2C%20%24atts%20%2C%20%24postid%20)%20%7B%0A%09%09%2F%2F%20return%20as%20array%0A%09%09if%20(%20%24string%20)%20return%20%24string%3B%0A%0A%09%09%2F%2F%20check%20if%20it’s%20an%20array%0A%09%09if(is_array(%24value))%20%7B%0A%09%09%09%2F%2F%20loop%20over%20the%20array%0A%09%09%09foreach(%20%24value%20as%20%26%24sub_item)%7B%0A%09%09%09%09%2F%2F%20type%20juggle%20the%20sub_item%20to%20an%20object%0A%09%09%09%09%24items%5B%5D%20%3D%20(object)%20%24sub_item%3B%0A%09%09%09%7D%0A%09%09%2F%2F%20return%20the%20items%0A%09%09return%20%24items%3B%0A%09%09%7D%0A%09%2F%2F%20fallback%20to%20returning%20whatever%20was%20passed%20in%0A%09%2F%2F%20just%20in%20case%20anything%20changes%20to%20the%20code%0A%09return%20%24string%3B%0A%7D” message=”” highlight=”” provider=”manual”/]

And that’s it! This filter gets a very high priority (90 so that it runs late) so that any other filter can return a value if that’s what we want and we escape early. So now, if for some reason you DON’T select a subfield in the repeater-connector you can just pass on the whole repeater as objects, Which the Accordion Module uses as the items-list.

Just look at the video to see what that may look like.


Toolbox has added the filter mentioned in step 3 to core. This means you don’t need to paste that code into your functions.php.

The repeater field has 3 options in it’s original form (remember, you can add your own):

  1. You’ve entered ‘something’ in the Twig template field. It will ignore everything else and process it. Even if you just entered a single character space, it is a viable return value and will be returned as a value. Timber Libraby-plugin needs to be activated for this.
  2. Twig template field is completely empty and you entered something into the field called ‘subfield’. If you want it to return a subfield called ‘content’, and the first iteration of that repeater, you enter ‘content[0]’ because it is zero-based.
  3. Both template field and subfield are empty. It will return the repeater field as an object.


Posted in , ,


Web ninja with PHP/CSS/JS and Wordpress skills. Also stand-in server administrator, father of four kids and husband to a beautiful wife. Always spends too much time figuring out ways to do simple things even quicker. So that you can benefit.