New looper providers / ACF repeater field

Loving the updates in 4.1 and have been trying out the new conditional display options which works great…

I was just reading the release notes sections about the new provider types - in particular “custom” and “array” and was trying to get my head around if/how these can be used to display ACF repeater fields. I’ve played around with it for half an hour without much success and wonder if I’m just barking up the wrong tree with this…

Anyone with comments/ideas about this would be much appreciated. Thanks!

1 Like

Can’t help you with this, but I will add my vote here for looping over ACF repeater fields!!!

I had a bit more of a play around and I think I got it working - not sure if this is the right way to do it though…

I made an ACF repeater called “systemer” and added this code to my functions.php:

add_filter( 'cs_looper_custom_my_project_data', function( $result ) {
    return get_field('systemer');
});

And to my great surprise it’s working! :slight_smile:

Looks very promising! Was this the only of code needed, or just the last bit? If so, what other things have you done/added earlier?
Does “systemer” then simply show up under “taxonomies” in the Query builder of the looper provider, or how do you access it? And how do you access the sub fields inside “systemer” in your looper consumer?

Followed the release notes… made a provider like this:
Screenshot 2021-01-26 at 22.24.08

Then this in a text field to display the sub-field of my repeater. Which in this case was called “name”:

{{dc:looper:field key="name"}}

Thank you!

Nice job @spedney! Glad to see you got something working.

This is high priority feature request on our end. There will be first class support for ACF Repeaters and even nested repeaters. We’re also going to revisit how we retrieve those fields and find ways to pull ACF data from taxonomy terms as well. I can’t promise an ETA, but I’m anticipating it being part of the next release cycle.

1 Like

Just a quick thought that may help here after seeing your code. Try this:

add_filter( 'cs_looper_custom_my_acf_repeater', function( $result, $args ) {
    return get_field( $args['field'] );
}, 10, 2);

Then you can set the hook to my_acf_repeater and use the Params (JSON Editor) to include this:

{
  "field": "systemer"
}

That will give you the ability to name your repeater field instead of needing to defined multiple custom loopers on the PHP side.

Thank you Alexander! This will make it even more convenient. Indeed, I had to define several custom loopers.
I have a related question. One of the repeater fields I have is a “Q&A”, with a question and an answer in each of the repeats. I want to display the Q&A with an accordion. The accordion element itself does not have the option to set it as a looper provider and/or consumer. I got it to work with the following layout: The parent Row is the looper provider, and the accordion is placed inside a Div. The Div is the looper consumer, consuming the ACF repeater field. The header of the accordion item then receives the “Question”, and the Content receives the “Answer”, each as dynamic content. This works.
image
Problem (maybe): This results in the generation of several accordions, each with 1 Q&A item, rather than 1 accordion with several Q&A items. Functionally, there is no difference at the front end (If one wants the feature that only a single accordion item is open at once, one has to explicitely name the “Custom Group”, because it is several independent accordions).
Are you planning to make Accordions loopable in the future? Would there be a hit on performance with multiple accordions?

Thanks Alexander, that worked even better! I was able to use it both for a repeater field and also for a gallery. Thanks for all your good work, really enjoying all these improvements :slight_smile:

@striata I see what you mean there with the Accordions. I’ll look into the possibility of allowing Looper controls within the Accordion elements themselves.

@spedney Awesome! That’s great to hear.


In regards to the topic of ACF in general, I can confirm we’ve been able to get Loopers working with ACF relational fields as well. You’ll be able to do stuff like access a list of Posts, Terms, etc. that come from any ACF source and loop over them. This will be coming in Pro 4.2 which we’re tentatively planning on releasing early March.