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);
}