Home Forums ACF PRO add_row doesn't act like expect


add_row doesn't act like expect

  • Hi there,

    on I have a ACF-form with a repeater-field from which I want to use the values to store them as values of another repeater-field in the post. The $post_id is given via acf/pre_save-Filter in the site containing the form itself. In the example it’s 3891. The repeater-field of the post contains three sub_fields, called “last_name”, “first_name” and “age”. Same for the other repeater-field.

    I use the following code

    add_action('acf/save_post' , 'jk_update_field_of_attendees');
    function jk_update_field_of_attendees( $post_id ) {
    	if (isset ($_POST['acf']['particpate'])) { //to check if this is a specific form
    		if (have_rows('field_6073f48e873ad')) { //the repeater-field of the form
    			while ( have_rows('field_6073f48e873ad') ) {
    				the_row(); //start the loop
    				$row = array (
    					'last_name'		=>	get_sub_field('last_name'),
    					'first_name'	=>	get_sub_field('first_name'),
    					'age'			=>	get_sub_field('age'),
    				); //collect the data from the form
    				$new_row = add_row('field_606f0eaebf349', $row, $post_id); //try to add the new row to the correct repeater-field of the post.

    When I submit the form the data is stored in the repeater-field of the form (called “helfer” – German for “helpers”) but not in the correct repeater-field (called “teilnehmer” – German for attendees).

    Any advice? What am I doing wrong?

    Thank you so much 🙂

    All the best

  • Solved it by myself. The action needs the $post_id. So I return it within the function. Also I’ve forgotten to use the $post_id to call have_rows. Nothing to do here anymore.

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.