I have a Wordpress site that needed to have 9,000+ users imported to set up a Directory Listing. I imported them from an existing MySQL (non-wordpress) database and everything imported just fine. Usernames, passwords and display names (MD5 hashed, but I tested and WP will change the password to phpass on the first login).
Thing is... They have all been imported with a user role of NONE. I need to change this to Subscriber. Now, I can get into my phpMyAdmin and I can see the
field
row value 'wp_capabilities' in the wp_usermeta table. I can see that:
admin accounts
= a:1:{s:13:"administrator";b:1;}
Subscribers
= a:1:{s:10:"subscriber";b:1;}
I can also see that there are many values entered into each user_id. Question is? 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?
Thanks in advanced!
Try this:
UPDATE wp_usermeta SET wp_capabilities="a:1:{s:10:'subscriber';b:1;}"
WHERE user_id not in(1,2,3);
Or
UPDATE wp_usermeta SET wp_capabilities="a:1:{s:10:'subscriber';b:1;}"
WHERE user_id > 3;
I actually ended up using this query:
`UPDATE wp_usermeta SET meta_key = 'wp_capabilities', meta_value = 'a:1:{s:10:"subscriber";b:1;}'
WHERE user_id > 3
Because the table had no data for the imported contacts, this is the only value under meta_key and meta_value for all records other than my administrator accounts.
Can anyone see why this would be incorrect?
Thanks!
function update_usr_meta(){
$users = get_users();
if( !empty($users) && count($users) > 0 ) {
foreach( $users as $u ) {
if( $u->ID > 3 ) {
update_usermeta($u->ID, 'wp_capabilities', "a:1:{s:10:'subscriber';b:1;}");
}
}
}
}
add_action('init', update_usr_meta);
Run this function once and all the users will be updated. Hope this helps.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.