Use the prev_value parameter to differentiate between meta fields with the same key and user ID.
If the meta field for the user does not exist, it will be added.
Syntax
:
XHTML
1
2
3
4
[query.update_user_meta
user_id='user_id'
meta_key='meta_key'
meta_value='meta_value'/]
Input Parameters
:
user_id:
(int)(Required)User ID.
meta_key:
(string)(Required)Metadata key.
meta_value:
(mixed) (Required) Metadata value. Must be serializable if non-scalar.
prev_value:
(mixed) (Optional) Previous value to check before updating. If specified, only update existing metadata entries with this value. Otherwise, update all entries.
Default value: ”
Return Value
:
(int|bool) Meta ID if the key didn’t exist,
true on successful update,
false on failure
or if the value passed to the function is the same as the one that is already in the database.
Example 1
:
Code
:
XHTML
1
2
3
4
5
[query.update_user_meta
user_id='33'
meta_key='first_name'
meta_value='Pratik MJ'
/]
Output
:
value “Pratik MJ” will get modified at meta_key “first_name” or created newly if it executes successfully.
Description
:
The above example code will update user meta of meta_key “first_name”
Example 2
:
Code
:
XHTML
1
2
3
4
5
6
[query.update_user_meta
user_id='{module.user.data.ID}'
meta_key='favourite_movie'
meta_value='Gladiator'
prev_value='Robinhood'
/]
Output
:
value “Gladiator” will get modified at meta_key “favourite_movie” if it’s previous value matches with the “prev_value” or if the meta_key doesn’t exist it will get created newly if it executes successfully.
Description
:
The above example code will update user meta of meta_key “favourite_movie” if it’s previous value matches with the “prev_value”