Home › Forums › Add-ons › Repeater Field › Repeater inside a group › Reply To: Repeater inside a group
In both sets of code you are resetting the value to an empty array and then updating the field on each loop. This means that only the last value will exist when done.
You need to build the repeater and update with all rows at the same time
going by your first code
$group_key = 'field_64e765bfc42ef';
$repeater_key = 'field_64e76f9210338';
$group_value = array();
$repeater_value = array();
foreach ($event->lineup as $item) {
// add row to repeater
$repeater_value[] = array(
'field_64e770e717754' => $item->details,
'field_64e770f317755' => $item->time
);
} // end foreach row
$group_value = array(
$repeater_key => $repeater_value
);
Now you can update the group field with the group value.
Also, do not forget that if the group, or the repeater has any values other than these fields then you will need to get the current value of the group field and modify that existing value instead of starting with nothing.
To get the value of the existing group before you updated in
if (have_rows('group_field_name')) {
// group field always true
while (have_rows('group_field_name')) {
// always happens 1 time for group fields
// the row returns an array with field key => unformatted value pairs
// ready for use in update_field();
$group_field_value = the_row();
}
}
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.