Solved

Mass Delete WordPress Subscribers with MySql Query

Posted on 2011-03-21
5
1,158 Views
Last Modified: 2012-05-11
Hi, I have this query to select my wordpress subscribers, but, now I need to delete them. Can someone help me change this to work?

I would need to delete their rows from the wp_users table and all associated data from the wp_usermeta table.

SELECT user_id, user_id 
AS ID, user_login, display_name, user_email, meta_value 
FROM wp_users, wp_usermeta 
WHERE wp_users.ID = wp_usermeta.user_id 
   AND meta_value LIKE '%subscriber%' 
ORDER BY wp_usermeta.user_id

Open in new window

0
Comment
Question by:adrian7474
  • 2
  • 2
5 Comments
 
LVL 2

Expert Comment

by:stopReplying
ID: 35189299
CREATE TABLE temptable (temp_id VARCHAR(250) PRIMARY KEY);
INSERT temptable(temp_id)
SELECT wp_users.user_id FROM wp_users, wp_usermeta
WHERE wp_users.user_id = wp_usermeta.user_id
AND meta_value LIKE '%subscriber%'
ORDER BY wp_usermeta.user_id;
DELETE from wp_users where user_id in (select temp_id from temptable);
DELETE from wp_usermeta where user_id in (select temp_id from temptable);
DROP TABLE temptable;

Open in new window

0
 
LVL 31

Expert Comment

by:gwkg
ID: 35224413
You can use wp_delete_user() , especially if you need to reassign any posts.

http://codex.wordpress.org/Function_Reference/wp_delete_user

If you look at the code wp_delete_user() also calls clean_user_cache() before deleting the user
http://phpxref.ftwr.co.uk/wordpress/nav.html?wp-admin/includes/user.php.source.html#l258
0
 
LVL 2

Expert Comment

by:stopReplying
ID: 35400846
After some thinking, I found a way that does that without you running any queries, scripts or anything...
Go to your Wordpress Dashboard, go to Users, click on Subscriber, check the checkbox left to the "Username", select from "Bulk actions" Delete, click Apply.

How to delete all subscribers within Wordpress Dashboard
0
 

Accepted Solution

by:
adrian7474 earned 0 total points
ID: 35931296
Sorry, I have over ten thousand users. This would take all day to do. I ended up finding this query solution.

#Run this first ////
DELETE FROM insider_users
WHERE ID NOT IN (SELECT post_author FROM insider_posts)
# Then run this ///
DELETE
FROM insider_usermeta WHERE user_id NOT IN
(SELECT ID FROM insider_users)

Open in new window

0
 

Author Closing Comment

by:adrian7474
ID: 35957287
Found my own solution.
0

Featured Post

Control application downtime with dependency maps

Visualize the interdependencies between application components better with Applications Manager's automated application discovery and dependency mapping feature. Resolve performance issues faster by quickly isolating problematic components.

Join & Write a Comment

Suggested Solutions

WordPress is constantly evolving, and with each evolution appears to get better and better.  One of the big drawbacks prior to version 3 was that there was no way to be able to set up a custom menu from the backend. The Old Way Adding menus is…
Introduction Since I wrote the original article about Handling Date and Time in PHP and MySQL (http://www.experts-exchange.com/articles/201/Handling-Date-and-Time-in-PHP-and-MySQL.html) several years ago, it seemed like now was a good time to updat…
The purpose of this video is to demonstrate how to insert an Iframe into WordPress. This will be demonstrated using a Windows 8 PC. Go to your WordPress login page. This will look like the following: mywebsite.com/wp-login.php : Open Page or Post…
The purpose of this video is to demonstrate how to prevent comment spam on a WordPress Website. This will be demonstrated using a Windows 8 PC. Plugin Akismet will be used. Go to your WordPress login page. This will look like the following: myw…

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now