I am trying to: save data entered on generic field to custom user meta field
I am using the following function to save data from a generic field to a custom user meta field
add_action('cred_save_data', 'user_imob_func',10,2);
function user_imob_func($user_id, $form_data)
{
// if a specific form
if ($form_data['id']==682)
{
if (isset($_POST['imobSelect']))
{
// add it to saved user meta
update_user_meta($user_id, 'wpcf-imobiliaria', $_POST['imobSelect'], true);
}
}
}
The field is a select field populated by a view listing a post type called Imobiliária.
The new user is created, but the Imobiliaria field is empty.
That will create a debug file called debug.log in your wp-content folder which you can examine in any text editor, and you should see the expected value submitted with the form there.
If not the problem is earlier, i.e. in creating your generic field in the first place.
I just double-checked this worked on my test site and didn't experience any problems.
I also tried an alternative. Because you want to save the custom user field when the form is submitted you can take advantage of the option "persist":1 which you need to manually add to your generic field for it to be saved to the database.
That will automatically save the field as user meta (note you need to include the wpcf- prefix if you are saving a Types field.
So that's an alternative you could try.
With your current set up, when you say the field isn't saved, what kind of field is the corresponding Types field (wpcf-imobiliaria)?
If it were a select field where you had defined several options with values & labels and the value stored in the database didn't match the value where you defined the custom user field then when looking at the user profile it would appear that nothing was selected, even though something was saved in the database.
So I would inspect the wp_usermeta table to see whether a wpcf-imobiliaria field had been saved, but with a non-matching value.