Home › Forums › Add-ons › Repeater Field › How to add new row in repeater under some group programatically › Reply To: How to add new row in repeater under some group programatically
G’day mate,
The proper function you are looking for to add/edit a entry to the repeater field is called update_row
.
https://www.advancedcustomfields.com/resources/update_row/
And, the proper hook you are looking for is acf/save_post
, which gets triggered after the entered acf values are saved.
https://www.advancedcustomfields.com/resources/acf-save_post/
To combine the above 2 resources, your code should look something similar like:
add_action('acf/save_post', 'insert_that_very_special_row');
function insert_that_very_special_row($post_id) {
// get how many rows is already in the database first,
// cause we need to insert our row by index
$row_count = count(get_field('attributes_cargo_pick', $post_id)?: []);
// the new row that we wanna add
$row = ['pcs' => 1, 'bol' => 2, 'size' => 3];
// update it as the next index (++$row_count)
update_row('attributes_cargo_pick', ++$row_count, $row, $post_id);
}
Cheers 😬
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!
2022 was a big year for Advanced Custom Fields, with more capabilities, a new generation of ACF Blocks, a refreshed UI, and a new home. Our year in review post looks at advancements we’ve made and offers a glimpse of the future.
— Advanced Custom Fields (@wp_acf) January 6, 2023
https://t.co/HahJUCcyH4
© 2023 Advanced Custom Fields.
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 Cookie Policy. If you continue to use this site, you consent to our use of cookies.