i'm kinda stucked right now and would appreciate some help!
I want to save the input from a gravity form into the users profile meta but it's a form users do more often so i need the value to be safed in a list everytime it gets submitted - In the meta profile i'm using a custom textarea field to store the values.
Right now I'm using this code and it stores it one time but always overrides the recent value with the new value:
add_action("gform_after_submission_9", "gravity_post_submission", 10, 2);
function gravity_post_submission ($entry, $form){
//Gets field id 10
$values = rgar( $entry, '19' );
update_user_meta( get_current_user_id(), 'keywords', $values );
}
But i need the value to be saved everytime in a new row of the meta textarea field and not be overwritten.
You guys have an idea how i will be able to archieve this?
CodePudding user response:
Would this work?
add_action("gform_after_submission_9", "gravity_post_submission", 10, 2);
function gravity_post_submission($entry, $form){
$value =$entry['19'];
$meta_value = get_user_meta(get_current_user_id(), 'keywords', true);
if (!empty($meta_value )){
$meta_array = explode(",",$meta_value);
array_push($meta_array, $value );
update_user_meta( get_current_user_id(), 'keywords', implode(",",$meta_array ));
}else{
update_user_meta( get_current_user_id(), 'keywords', $value );
}
}