ACF repeater fields in Gutenberg blocks

Hi Guys, does anyone know how to implement repeater fields inside pinegrow new block building? We use the repeater function a lot in websites so I was wondering how Pinegrow supported that?

You can do it, I’ve done it myself a few times. It is only possible to do it with the PHP code action, not the ACF field action though.

Here is the procedure:

Make a span around the html elements that you want repeated (technically you don’t need the span per se but in my opinion, this makes it easier to implement from a workflow standpoint) and add a PHP code action to it in the wordpress tab. Next, copy the top part of your repeater code into the field labeled “function with params” (for instance: if( have_rows(‘block’) ): while ( have_rows(‘block’) ) : the_row(); , just replace the “block” monicker here with the name of the repeater field) and set the ‘replace’ select field to “insert before”.

Next, add another php code action to the same element and paste the following code into it: endwhile; else : endif;.
And set the ‘replace’ select field to “insert after”. What this will do is wrap your chosen html elements into a repeater function. (You could also add the php code actions to the first element and the last element respectively, instead of doing this with a span. It will give exactly the same result but as I said earlier, I prersonally prefer using a span).

Than add a block action to the element encompassing that. (For instance, another span, wrapping the span you used for the php code actions).

Make sure you set the field group location where your repeater field is located to the acf block you registered with the block action.

Let me know whether you get it working.

1 Like

Thanks for the detailed response, wasn’t expecting that. Ill try this out. Thank you

Did it work for you?

Just wanted to say Thank you to Roel for the detailed guide. I followed your guide and It worked :+1:

1 Like