tags:

views:

47

answers:

2

Is there a way to delete all WordPress authors which have 0 posts?

A: 

Go into the admin panel and delete them?

Or do you have thousands to delete?

John at CashCommons
Assume there are thousands.
Robert Harvey
I literally have 1000s of users. It's not that my blog is very popular - but many of the users are automatically generated. So deleting them one by one is rather tedious.
bosh
+1  A: 

To see each user and the number of posts of which he or she is the author:

select user_login, (select count(*) from wp_posts where post_author = wp_users.ID)
from wp_users

I'm not sure if it's safe to just delete rows from the wp_users table just because the user hasn't posted anything. There may be references to the account from other tables. It should, however, be safe to set the password:

update wp_users wp_users left join wp_posts on wp_users.ID = post_author
set user_pass = 'blocked'
where post_author is null
Vebjorn Ljosa
That's the question - how to keep the WP DB tables consistent when deleting users.
bosh
Combine that SQL to search and iterate over the results and use the `wp_delete_user` function to delete the user.
Gipetto