I’m creating a user and I want to add a metadata "Age" numeric.
The problem is that when I add it, it adds it as string
$user_id = wp_insert_user( array(
'user_login' => 'janedoe',
'user_pass' => 'passwordgoeshere',
));
add_user_meta($user_id, 'Age' , 20);
wp_set_current_user($user_id);
var_dump(get_user_meta( get_current_user_id(),"Age"));
This is the result
Array (1) {
[0] =>
String (2) "20"
}
Why do not you pick it up as int?
Thanks
2
Answers
$meta_value
ismixed
type to save all variable types, it doesn’t know when the value is an integer or a string. So basically, it will convert/sanitize all variables to string.You can find out more at https://developer.wordpress.org/reference/functions/add_user_meta/
Hyy
Try this,