Save custom user meta on registration


I’m trying to create my own registration form and adding phone number as required field and I would love to save that phone number as custom user meta.

After validation and santizing inputs, ets. my code looks like this:

// this returns the correct value etc. - string(9) "126777889"

$user_id = wp_insert_user($fields);
add_user_meta( $user_id, 'user_phone', $metas['user_phone'] );

The user is created correctly, but there is something wrong with the phone meta field – in backend it looks like this:
enter image description here

I also tried this approach to test whether the meta exists:

if(get_user_meta($user_id,'user_phone')) {
} else {

Also tried to add the meta with ‘user_register’ action like this:

function addMyCustomMeta($user_id,$meta) {

And then using like this:

$user_id = wp_insert_user($fields);

In all cases I end up with the situation described in the picture above.
No meta title and the value is saved as multiple “Array”

In database it looks fine:

enter image description here

Do you have any idea what am I doing wrong?

Thank you

Cafourek 4 months 0 Answers 13 views 0

Leave an answer