Setup a repeater field, in this example we'll call it "example-row"
and you give it the following sub fields:
- example-name, text
- example-phone, text
- example-image, image, returns URL
in your post content setup the shortcode like this:
[acf_repeater field="example-row" sub_fields="example-name, example-phone, example-image"]
User: %example-name%
Phone: %example-phone%
profile pic: %example-image%
[/acf_repeater]
notice how the list of comma separated items within the sub_field
attribute become %variables% accessible within the repeater shortcode. This allows you to create a template row for your repeater. These items get trimmed so spaces around the commas in the list are ok.
You can NOT nest repeater shortcodes as library is right now. If you need to then I would recommend adding more shortcodes with different names but pointing to the same function like this:
add_shortcode("acf_repeater", "my_acf_repeater");
add_shortcode("acf_sub_repeater", "my_acf_repeater");
and now you can nest it.
[acf_repeater field="example-row" sub_fields="example-name, example-phone"]
<div class="user">User: %example-name%</div><div class="phone">Phone: %example-phone%</div>
[acf_sub_repeater field="example-sub-row" sub_fields="sub-item1, sub-item2"]
%sub-item1% %sub-item2%
[/acf_sub_repeater]
You can put nested repeaters adjacent to each other, you just can't nest it again. For that you'll need to make more shortcodes
[acf_sub_repeater field="example-sister-row" sub_fields="sub-item1, sub-item2"]
%sub-item1% %sub-item2%
[/acf_sub_repeater]
[/acf_repeater]
TODO: Figure out a better way to handle nesting rows without having to create more copies of the shortcode.
Hi! Thanks for sharing this. Could be just what I need to show some repeater fields on my page with Elementor, as it does not seemlike they support those fields for dynamic content yet.
I get a fatal error though when activating the plugin. because I am missing the post_id, I just left it at null (since it was optional), but that doesn't work :)
Let's say I want to show this field on the author archive, so it needs to load the field from the same user profile that is being viewed. Would I need to change the post_id all over? Any help will be appreciated :) Thanks