Home › Forums › Add-ons › Repeater Field › Add Repeater Row From Another Field › Reply To: Add Repeater Row From Another Field
Sigh, sometimes I feel like when I post here, the solution is about 5 minutes away. Turns out that I was missing the $post_id
in the add_row()
function.
So, the code that I have and is now working is:
function add_repeater_row_on_save($post_id) {
$my_textarea = get_field('my_textarea'); // My textarea field
$row = array( // my repeater sub-field
'field_1s' => 'Repeater sub-field 1 text',
'field_2S' => 'Repeater sub-field 2 text',
'field_3s' => 'Repeater sub-field 3 text',
);
$i = add_row('field_repeater', $row,$post_id); // The $post_id here was missing
// Reset Textarea
update_field('my_textarea', '', $post_id);
};
add_action('acf/save_post', 'add_repeater_row_on_save', 20);
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.