I think you are not handling the array part correctly.
The right syntax is –
$new_role = array("advocate" => 1);
The syntax that you have used is shown when you print some array on your screen but it should be written in above format in your PHP code. Currently, you are capturing it as a string and not an array.
Related Posts:
- add_user_meta() vs update_user_meta()
- Get basic Image Uploader on User Profile Page
- Return all users with a specific meta key
- Capabilities Vs User Meta
- Problem storing arrays with update_user_meta
- wp_get_current_user always returns 0
- get_users is expecting unserialized meta_value
- how to get specific fields from get_user_meta()
- Validating a new user registration field
- Check if WP_User_Query ‘include’ is empty
- User meta to post
- Add profile field (usermeta) to Add New User
- very last action before during user registration before he is redirected to homepage
- How to Make admin Sidebar Menu always be Collapse by code
- get_users / WP_User_Query returns empty when logged out
- How to query users by meta value, even when meta key doesn’t exist?
- Add a member number to new user
- Hook or action to save profile fields at specific time
- How to get the user description with get_users?
- get current user not working
- No first_name or user_firstname property in WP_User object
- Possible bug: update_user_meta is updating two unique meta entries
- How to display current_user bio
- Store user’s registration date as meta
- How to tell whether a user meta value has increased or decreased [closed]
- Filter WooCommerce Orders query with user meta data
- update_user_meta() not working
- How to display user’s avatar on their profile page?
- WP_user_query throws a 404 error
- Incrementally add or substract from usermeta field
- set a user-meta key as avatar
- ‘profile_update’ hook alternative for WooCommerce user meta data
- Prevent update of custom user profile meta field on the front end after 1st entry
- Make this Fast and Queryable
- update_user_meta after wordpress in action hooks
- Adding user data to an existing user_id
- Problem to wp_hash
- trying to determine if meta value exists for user and if not auto submit gravity form to redirect
- action user_new_form param is a string
- Customize Avatar using user meta
- get_user_meta returning old data
- Why does the usermeta table contain html entities?
- How can I programmatically show a specific (template) page, like author.php?
- WP_User_Query not returning users with meta – what am I missing?
- Multiple Email Addresses, One User
- Randomize Users
- Fetch user related data
- “Select your country” landing page. Remember user choice
- How get meta from all users?
- Order By Meta_key but convert custom date to Y-m-d first
- Update user meta without lose of old data
- Using xprofile_insert_field
- Test if key is in user_meta array
- Combining wp_list_authors with get_user_meta
- Using WP for user management
- Show extra user profile meta for current user
- Pulling member name from WordPress URL
- Query Nickname rather than Display Name in custom Woocommerce plugin
- Add additional Fields for users and get value
- Remove fields from WordPress profile
- E-mail Update – Validation
- How to save a label for an extra user meta field and to display it later?
- Display user meta data from a textarea as a formated text
- gform_after_submission not working as expected [closed]
- Sort users by meta key value even if meta key not present for all users
- Wrong result in fetching User meta of WordPress
- Fetch user’s using Last Name
- How to display user_meta array as a table?
- How can I search user meta by a partial key name?
- how to get users with usermeta include array of an array
- get_user_meta value is stored within strange characters
- Update user meta when customer update their first name
- Delete user meta ( delete_user_meta ) by key without user id
- Why is my Custom User Meta deleted on Profile Update?
- wp_redirect not working after update_user_meta
- How to remove the url format from the WEBSITE field in the user registry?
- users joined group count in buddypress
- Edit a user profile field on front end
- SQL – Shorter way to query user and usermeta data
- Updating WooCommerce product field when product author updates profile field
- WP author meta disappeared
- Update a user meta key based on WooCommerce product purchase
- How to set a user meta key value based on another user meta key value
- How to get value from radio buttons meta box, and return different contents?
- Changing an array of IDs in the usermeta table to fit different format
- Using wp_login vs login_redirect to redirect based on user-meta
- Saving an array of values (file urls) to update_user_meta()?
- get user role value as a string from wp usermeta table into custom script
- Get currentuserinfo firstname and lastname
- Get meta value and associated user meta
- Store Foreach in user profile
- use single form to enter multiple profiles
- Allow users to create and store data and retrieve it on login
- How to access User meta data within a plugin
- Using IDX feed to display agent’s and listings with agent’s info associated for Real Estate Website
- user profile replace first name last name with custom values
- Custom user meta data [closed]
- WPML – how to translate user profile fields with icl_t()? [closed]
- Creating a Digital Download facility and track downloads [closed]
- Find matches of a variable in custom usermeta