How can I write a bulk MySQL command to add in the value
wp_capabilites=”a:1:{s:10:”subscriber”;b:1;}” into each user_id except
1, 2 and 3 ie. the newly imported users?
You don’t. That is a serialized array which is a PHP construct. MySQL has no idea what to do with it. To the database, it is just an string. To PHP it is a representation– a diagram– of an array and PHP takes it seriously. If you get a single character wrong in will not unserialize. If you were just copying a fixed string you might be able to pull this off with SQL
but you are not– “I can also see that there are many values entered into each user_id”. To “insert” date into those strings you would have to reproduce PHP serialize in SQL.
Let the Core do the work for you:
$args = array(
'exclude' => array(1,2,3),
);
$users = get_users($args);
foreach ($users as $u) {
$u->set_role('subscriber');
}
Related Posts:
- Programmatically changing role information; editing role name and deleting
- Find duplicate posts with same slug and author
- Set meta_key and meta_value for all registered user in wordpress using sql query [closed]
- How do I join a $wpdb query with user meta using default value if not exist?
- Paypal Post IPN handeling nightmare
- Import CSV to MySQL, with custom registration field information
- Run Username SQL Query from WordPress Child Theme Functions File
- Copy usermeta value where ID matches in the same table
- How do I echo all users’ display_name and their meta_value who have a certain meta_key?
- How to search usermeta table
- Apache Redirect based on WordPress permissions
- MySQL error 2006: mysql server has gone away
- “INSERT IGNORE” vs “INSERT … ON DUPLICATE KEY UPDATE”
- Cannot delete or update a parent row: a foreign key constraint fails
- #1273 – Unknown collation: ‘utf8mb4_unicode_520_ci’
- Host ‘xxx.xx.xxx.xxx’ is not allowed to connect to this MySQL server
- PHP Deprecated: Methods with the same name as their class will not be constructors in a future version of PHP
- what does “/index.php?admin/admin_dashboard” in my url mean
- How to join two tables by multiple columns in SQL?
- How to get size of mysql database?
- SQL – Update multiple records in one query
- MySQL Error 1093 – Can’t specify target table for update in FROM clause
- MySQL: Invalid use of group function
- mysqladmin: connect to server at ‘localhost’ failed
- mysql update multiple columns with same now()
- Usage of MySQL’s “IF EXISTS”
- Generating a random & unique 8 character string using MySQL
- MySQL > Table doesn’t exist. But it does (or it should)
- Getting java.sql.SQLException: Operation not allowed after ResultSet closed
- How to create a foreign key in phpmyadmin
- Can’t create test file lower test start server mysql
- MySQL delete multiple rows in one query conditions unique to each row
- SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo failed: Name or service not known
- CAST to DECIMAL in MySQL
- Failed to Connect to MySQL at localhost:3306 with user root
- How do you properly prepare a %LIKE% SQL statement?
- wp_update_user not updating
- Optimize Multiple Taxonomy Term MySQL Query?
- What specific database privileges does WordPress need?
- Using source control with WordPress
- SQL query to update post_date (one post = one single date & time)
- wpdb prepare syntax
- How to run this SQL query of wp_terms database
- Proper way to work with wpdb to get user’s firstname
- How to change post format from Aside to Image for all posts?
- SQL User Query by Multiple Roles using PHP
- Inserting Hundreds of Thousands of Posts at Once
- wp_admin edit.php slow with lots of queries
- How to add and SQL query of posts only published
- Slow Mysql Queries
- can database and media folder be moved to a different drive?
- query users by role
- How to Create a Admin User for A WordPress Site via MySQL (PHPMyAdmin)?
- Select Multiple meta_value from WP DB; Single Query
- Within the database, where is the flag which says that a user has Super Admin rights?
- writing inner join in wpdb
- How to get data from WordPress site sql file
- Unknown collation when I import a dump from an existing site into a development database?
- PHP script can’t connect to Database on port 3307
- Display user meta by different user role
- WordPress with php5-fpm and nginx
- When WordPress Default table, Echo Success. When Plugin Table, Echo Blank
- How to create user specific pages (not user role!)?
- Users create/join groups
- How to translate this mySQL query to $wpdb query
- $wpdb to insert html form information
- Proper usage of $wpdb->update()?
- MySQL 5.5 upgrade ‘broke’ WordPress [closed]
- Separate DB by yearly archive of WordPress
- What should a WordPress developer know about MySQL? [closed]
- Copyright: Get first and last date of post type
- Update MySQL query so that it functions again
- Is there a page length limit?
- Query posts by custom taxonomy and sort by post_modified
- WordPress $wpdb get posts from category and sort by custom meta
- Some Post Content Does Not Show Up In DB Search
- Array Formation Issue
- Migration problems with mysql: Operation not allowed when innodb_forced_recovery > 0 [closed]
- wp_usermeta – Read from database, but save function broken
- WordPress $wpdb no result
- How can I view my site directly from WordPress dashboard?
- Word Press and database from another server sync
- when using $wpdb sudden connection rejection without changing anything. Access denied, with errors from repair tool
- When I add metadata, metavalue length is added in to the value in some cases
- edit_user_created_user hook – using to update Groups
- Mysql Error in querying form entries in Gravity Form plugin
- WordPress database error Duplicate entry for key ‘slug’
- Improving performance of SQL sub-queries in WordPress
- Saving custom term value to the database in new table
- MySQL errors after a WordPress clone
- How to restore: Database intact but folders deleted
- XML RPC post produces immediate revision with odd post_date_gmt
- MYSQL Join on meta key value?
- Display and Allow users to edit their own profiles
- Complicated MySQL Query
- problem with quotes on new post
- Initialization of table in database using ‘CREATE … IF NOT EXISTS’
- mysqldump throws: Unknown table ‘COLUMN_STATISTICS’ in information_schema (1109)
- How do I load a sql.gz file to my database? (importing)
- Batch Replace URLs in WordPress Database