Solved

Mass Delete WordPress Subscribers with MySql Query

Posted on 2011-03-21
5
1,194 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

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

How to create your own WordPress Theme Before I begin with the theme design tutorial, I would like to give you the basics of what is required to make a WordPress Theme. The most basic WordPress theme only requires 2 files: a style.css file and an…
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
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 integrate Mailchimp with WordPress, by placing a Mailchimp signup form on a WordPress Page or Post. This will be demonstrated using a Windows 8 PC. Mailchimp will be used. Log into your Mailchi…

777 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