Solved

Mass Delete WordPress Subscribers with MySql Query

Posted on 2011-03-21
5
1,217 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Optimize the query 5 50
Wordpress Security 29 71
htaccess block all countries but the US 4 35
Dynamic Table mySQL stored procedure 5 31
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…
Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
The purpose of this video is to demonstrate how to set up an RSS Feed on a WordPress Website. This will be demonstrated using a Windows 8 PC. Feedburner will be used for this demonstration. Go to your WordPress login page. This will look like the…
The purpose of this video is to demonstrate how to set up basic WordPress SEO. This will be demonstrated using a Windows 8 PC. The plugin used will be WordPress SEO by Yoast. Go to your WordPress login page. This will look like the following: myw…

740 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