Home › Forums › ACF PRO › Adding rows in a repeater field while in a For loop › Reply To: Adding rows in a repeater field while in a For loop
It seems your code is creating a new value and replacing the repeater field for every image you have. You should do it like this instead:
$arrayCount = count($feed['Images']);
// set the variables first
$field_name = 'repeater_field_name';
$field_key = 'field_583ea1bfe02e9';
// get the existing value
$value = get_field($field_name, $propertyID);
// add the new values
for($i = 0; $i < $arrayCount; $i++) {
$value []= array(
'order' => $feed['Images'][$i]['Order'],
'primary_image' => $feed['Images'][$i]['IsPrimaryImage'],
'id' => $feed['Images'][$i]['Id'],
'url' => $feed['Images'][$i]['Url'],
'document_type' => $feed['Images'][$i]['DocumentType']['DisplayName'],
'document_sub_type' => $feed['Images'][$i]['DocumentSubType']['DisplayName'],
);
}
// update it
update_field($key, $value, $propertyID);
Don’t forget to change the “repeater_field_name” value with your repeater field name.
I hope this helps 🙂
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.