I’m trying to add a new row in a nested repeater field with PHP (I don’t use acf_form).
I know in what row of the parent repeater I want to get to work (
But I can’t find out how to add a new row in the repeater that is in
What I have tried is this:
$parent_field = 'field_5791d60e83186'; $target_row = $parent_field[$row_number]; $target_field = $target_row[field_57d55571d9eb2]; $add_row_data = array ('reactie' => $new_reactie, 'reactie_datum' => $new_reactie_datum); add_row( $target_field, $add_row_data);
This produces absolutely nothing.
Does anyone know the right syntax to do this.
I’ve looked at
update_sub_field but that doesn’t help either.
Isn’t there something like
I believe you should be able to do it by using the
update_field() function like this:
$row_number = 0; $post_id = 85; $repeater_key = 'field_1234567890abc'; $repeater = get_field('parent_repeater', $post_id); $repeater[$row_number]['child_repeater']['child_subfield'] = 'added'; update_field($repeater_key, $repeater, $post_id);
I hope this helps 🙂
But I gave up!
No matter what I try or do, I just couldn’t get it to work.
But I have found another solution.
I removed the nested repeater and made it a normal not nested (stand-alone) repeater.
The (formerly) parent repeater now has an extra field with a unique number for every row.
The (formerly) child repeater also has an extra field for every row that corresponds with the unique number of one of the rows in the parent repeater.
All I have to do now is keep these numbers in sync, which is not that hard.
And now I can update the (formerly) child repeater with simple instructions like
This might not be the most ideal solution, but it works for me.
After trying and testing for a couple of days with nested repeaters, I got this solution working in less then an hour. And the results are almost the same.
You must be logged in to reply to this topic.
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!
🤔 Curious about the ACF user experience? So are we! Help guide the evolution of ACF by taking part in our first ever Annual Survey and guarantee you’re represented in the results. https://t.co/0cgr9ZFOJ5— Advanced Custom Fields (@wp_acf) May 8, 2023
© 2023 Advanced Custom Fields.