I’m trying to update multiple meta_key for user in WordPress
update_user_meta( $user_id, array( 'nickname' => $userFirstName, 'first_name' => $userFirstName, 'last_name' => $userLastName , 'city' => $userCityID , 'gender' => $userGenderID) );
but it is not working. How can we update multiple meta_key for user?
Try:
So instead of passing your array to
update_user_meta
which only accepts string arguments for$meta_key
, loop over the array and callupdate_user_meta
for each key/value pair in the array.EDIT:
WordPress doesn’t give a built in way to update multiple metas at once. Part of the reason for using their built in function is because filters and hooks can be registered to operate on the meta information. These won’t be called if you update them directly.
That said, you can try something like this (code untested):
just try to add the value with the same meta key,and remember to set the third value to false just like
then when you get user meta with the meta key ,it will return like: