Support

Account

Home Forums Add-ons Repeater Field adding a row to a repeater

Helping

adding a row to a repeater

  • It is unclear to me where you would put an add_row() function.

    I added the following code to my functions.php file and it caused the white screen of death:

    function my_pre_save_post_x( 14560) {
    
    $row = array(
    	'game_date'	=> 'June 20, 1975',
    	'away_team'	=> 'Boston',
    	'away_score'	=> 0,
    	'home_team'	=> 'Cleveland',
    	'home_score'	=> 0,
    );
    
    $i = add_row('games', $row);
    }
    add_filter('acf/pre_save_post' , 'my_pre_save_post_x', 10, 1);
    

    Any clarification or an expanded example would be helpful.

  • Hi @bosoxbill

    I’m afraid you have some syntax errors in your code. I believe you need to do it like this instead:

    // You need to set the variable instead of the value here
    function my_pre_save_post_x( $post_id ) {
    
    $row = array(
    	'game_date'	=> 'June 20, 1975',
    	'away_team'	=> 'Boston',
    	'away_score'	=> 0,
    	'home_team'	=> 'Cleveland',
    	'home_score'	=> 0,
    );
    
    /* Please use the field key instead of the field name because you use it
     * before the saving process occured (pre_save_post). Also, you need to 
     * add the post ID to the add_row() function
    */
    $i = add_row('field_1234567890abc', $row, $post_id);
    }
    add_filter('acf/pre_save_post' , 'my_pre_save_post_x', 10, 1);

    To see the error message instead of the white screen, please take a look at this page: https://codex.wordpress.org/Debugging_in_WordPress.

    I hope this helps 🙂

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

The topic ‘adding a row to a repeater’ is closed to new replies.