update gallery field in repeater field advanced custom fields

1.1k views Asked by At

i need to implement a picture in a gallery field inside of a repeater field.

based on the update_sub_field function from acf i use:

update_sub_field( array('flat_repeater', $repeaterRow, 'gallery'), $attachmentId, $postId);

i cant loop through the repeater field so my selector for the update_sub_field function of acf is

array('flat_repeater', $repeaterRow, 'gallery')

where

'flat_repeater' = the name of the repeaterfield

$repeaterRow = the right row for the repeater where the gallery should be updated

'gallery' = the name of the gallery field

and

$attachmentId = the id of the image in the media library from wordpress

$postId = the post id where the repeater/gallery field is.

what am i doing wrong, cause it simply doesn't work.

greetings timotheus

2

There are 2 answers

0
Timotheus0106 On

i have solved it.

perhaps someone needs it sometimes..

the problem was the variable

$repeaterRow = the right row for the repeater where the gallery should be updated

i always used the key from the repeater array and that one starts with 0.

but repeater rows start with 1 ...

-,-

at leased its solved...

greetings timotheus

0
Doml The-Bread On

you need to use the field key as the 'name' of the repeater field

update_field('field_41hdk123', $arrayWithStuff, $postId);

i hope that solves your problems bro