Support

Account

Home Forums Add-ons Repeater Field Access Nth subfield of a repeater

Helping

Access Nth subfield of a repeater

  • How can I directly access a specific subfield from a repeater element, rather than looping through them as is shown in the docs?

  • Repeaters are stored in the format:

    repeater_name_X_sub_field

    Where X is the row number and it starts at 0. So the first row would be like repeater_name_0_sub_field, the next repeater_name_1_sub_field, etc.

    You can use that with get_post_meta to display a specific value, like:

    get_post_meta($post->ID,'repeater_name_0_sub_field',true);

    But depending on the field type you’re displaying, like if it’s something like an image or similar, that wouldn’t run it through ACF’s display process so you could have to do some work on your end there.

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.