Support

Account

Home Forums Add-ons Repeater Field Adding more rows to repeater field programatically

Solved

Adding more rows to repeater field programatically

  • I’ve looked at hundreds of examples and I can add the first row – even append a second row, but I cant add any more rows and its driving me crazy – possibly thisis because I’m not using the loop method or my array_unshift method is accessing the wrong array?

    This adds a second row with data but will then overwrite a row if I update the form

    if ( is_user_logged_in() ) {
    
        $user_id = get_current_user_id();
       
        $field_key = 'field_5bdc8d3c953f2';
        $value = array();
            $value[] = get_field($field_key, 'user_'.$user_id);
        $new_row = array('name' => $dogsname, 'sex' => $sex, 'rda' => $rda);
        array_unshift( $value, $new_row  );
        update_field($field_key, $value, 'user_'.$user_id);
    
    }
  • Fixed! This was a dumb mistake! Removed [] from $value

    if ( is_user_logged_in() ) {
    
        $user_id = get_current_user_id();
        $field_key = 'field_5bdc8d3c953f2';
        $value = get_field($field_key, 'user_'.$user_id);
        $new_row = array('name' => $dogsname, 'sex' => $sex, 'rda' => $rda);
        array_unshift( $value, $new_row  );
        update_field($field_key, $value, 'user_'.$user_id);
    
    }
Viewing 2 posts - 1 through 2 (of 2 total)

The topic ‘Adding more rows to repeater field programatically’ is closed to new replies.