You can use update_user_option()
function (see codex)
Your loop looks fine to me, so probably this would work:
// Create the WP_User_Query object
$wp_user_query = new WP_User_Query(array('role' => 'Subscriber'));
// Get the results
$users = $wp_user_query->get_results();
// Check for results
if (!empty($users)) {
// loop trough each author
foreach ($users as $user)
{
// update option
update_user_option( $user->ID, 'show_admin_bar_front', 'true');
}
}
Things to pay attention to:
-
You’re looping through all queried users, so in
update_user_option
the first parameter needs to be the id retrieved from current user
object (not the hardcoded ID) -
The third parameter in
update_user_option
should be of a string type apparently, so"true"
, nottrue
Related Posts:
- user_login vs. user_nicename
- Difference between update_user_meta and update_user_option
- Automatically delete inactive users after 2 months
- Show admin bar only for some USERS roles
- How to display custom user meta from registration in backend?
- Allowing an email as the username?
- Grouping users under parent user
- How to create a template for a custom URI associated with the user
- How to order users alphabetically by their last name?
- Extending WP_User class and using this sub-class during the whole lifecycle
- Wp_User_Query not sorting by meta key
- WP_User_Query with combined meta query – not working?
- How to use hyperdb to separate and share a user dataset between wordpress installs?
- \WP_User Object | What’s the Difference Between {caps} and {allcaps}?
- Show Biographical Info while creating new user
- include user profiles in search results?
- How to add follow functionality to multi-author wordpress site?
- Search multiple meta keys at once
- Where to Store Custom User Fields
- Plugin that would allow WordPress Authors to “follow” other Authors and query “Activity Info” from that
- Querying Email Addresses for a List of Users with Same Last Name?
- User profile custom field
- Front end user meta options for users
- ACF Upload Image in front-end with custom form
- Hide a user from WordPress
- Drop down list in user profile page
- Check for user meta data at Login
- How can I check if the admin bar is visible to the current user?
- Searchable meta value in user.php
- Delete user from frontend
- Memory usage for scalable usermeta queries
- stop login if user_status equal zero
- Does wp_delete_user() remove all user content?
- Log all users out of all locations after 24 hours
- How can i create an array user meta?
- Add user data to table when user is created?
- User Last Login Sort Column
- WordPress User Meta & ChromePHP or other way to debug/view php variables
- Use wp_update_user to update custom column in wp_users table
- Display users in order by an “order” custom meta field
- mysql query two database tables, users and usermeta and sort by custom meta int value
- Rest API code to get ID of current user not working: get_current_user_id() gives 0
- Updating wp_user_level on user update
- Should I encrypt the response that triggers an Ajax action? Is nonce sufficient?
- How can I attach a user to another user with user meta
- Creating user without username and password
- List users by meta_key and meta_value
- users and usermeta table
- WordPress SQL Issue not returning correct reselts
- User description only displayed for logged user
- How to pull all the contributer users records and order by Designation (which is users meta data)?
- cannot get user_registered date from get_user_meta
- “the_author_meta(‘url’)” not working inside “href”
- Assign random (and unique) user meta upon registration
- Display the line breaks in user bio without using html
- how to set default update_user_meta values wordpress
- Get user by meta key – WP multi site
- Add custom user meta data
- How to add an attribute to a user?
- New User Save Filter
- SELECT from wp_users, get Displayname too
- Assigning multiple or additional capabilities to specific users or how to create additional roles like bbpress roles?
- how do I add role and capability after I create a new user
- User Meta stuff
- delete_user_meta from a foreach results page
- How do I update user email from frontend input field?
- Reading additional fields in PMPro
- Can I add a unique code for each user based on the location?
- My custom user metadata is only active for only admin but i want it to be active on all users especially customers
- How to get image path from id using SQL
- Update user role for expired membership
- Get UserInfo from WordPress
- How can i add user display name drop down menu in frontend?
- Hook into add_user_role and update based on new and removed roles
- How to prevent multiple user accounts with the same meta field?
- How to Moderate Edits to User Profiles?
- Safely changing UserID’s, re-using deleted UserID’s and automatically using deleted userID’s instead of an increment
- meta_query orderby sort multiple keys
- How to update user meta from php file?
- REST_query_vars for users
- Require confirmation of current user’s email before updating database and before send_email_change_email
- Store extra user values permanently
- How do I change the user via SQL?
- Add method for tracking who referred new users
- Username has been exposed
- User list order by user meta
- User management missing after migration to new host
- Creating Custom user type just like custom post
- Validate user meta and redirect
- Let admin users edit member profiles from front end
- Does WordPress Need BuddyPress to Handle Large Amounts of Users?
- Sort users by custom user meta value
- Using and saving custom dropdown boxes on user profiles
- Store subscription details for users in WordPress
- Problem with update_user_meta() meta_value
- How to add custom detail page for a Subscriber at Admin Panel
- Add custom input field in new user page
- How can I list users by date in an array in meta_value?
- MySQL query to list users who never signed in
- Export user data from Squirrly’s Starbox plugin?