Title: Delete Orphaned Users
Last modified: August 22, 2016

---

# Delete Orphaned Users

 *  Resolved [msrebuildings](https://wordpress.org/support/users/msrebuildings/)
 * (@msrebuildings)
 * [11 years, 7 months ago](https://wordpress.org/support/topic/delete-orphaned-users/)
 * Hi
 * I have a problem with a multisite network where the database contains a lot of
   records for users who are attached to sites that no longer exist. A user is attached
   to a site, as far as I can tell, when they have a wp_##_capabilities record in
   the usermeta table, where ## is the blog ID.
 * So I need a way to delete the records from the users and usermeta tables where
   those users don’t have capabilities defined for specified sites. Does anyone 
   have any ideas? Happy to do with with a plugin or SQL.

Viewing 2 replies - 1 through 2 (of 2 total)

 *  [Mike Price](https://wordpress.org/support/users/castroboy/)
 * (@castroboy)
 * [11 years, 7 months ago](https://wordpress.org/support/topic/delete-orphaned-users/#post-5331053)
 * Hey there
 * I found a couple of things that might help you accomplish this task:
 * [https://wordpress.org/plugins/wp-orphanage-extended/](https://wordpress.org/plugins/wp-orphanage-extended/)
 * [http://wordpress.stackexchange.com/questions/126310/removing-orphan-users-in-wordpress-multisite](http://wordpress.stackexchange.com/questions/126310/removing-orphan-users-in-wordpress-multisite)
 * Good luck!
 *  Thread Starter [msrebuildings](https://wordpress.org/support/users/msrebuildings/)
 * (@msrebuildings)
 * [11 years, 7 months ago](https://wordpress.org/support/topic/delete-orphaned-users/#post-5331072)
 * After some playing around I realised it’s really simple with SQL, provided you
   have full database access.
 * I’m posting these as SELECT queries because you should run them that way first
   to check you have the right users before you DELETE. Anyone who doesn’t understand
   this should not try it!
 * `SELECT * FROM wp_users WHERE ID NOT IN (SELECT user_id FROM WP_usermeta WHERE
   meta_key = 'wp_##_capabilities')`
 * Your tables may have different prefixes.
 * You can use a similar query to delete records from other tables when they no 
   longer have a user in users.

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Delete Orphaned Users’ is closed to new replies.

## Tags

 * [db](https://wordpress.org/support/topic-tag/db/)
 * [delete](https://wordpress.org/support/topic-tag/delete/)
 * [multisite](https://wordpress.org/support/topic-tag/multisite/)
 * [sql](https://wordpress.org/support/topic-tag/sql/)
 * [user management](https://wordpress.org/support/topic-tag/user-management/)
 * [usermeta](https://wordpress.org/support/topic-tag/usermeta/)
 * [users](https://wordpress.org/support/topic-tag/users/)

 * In: [Networking WordPress](https://wordpress.org/support/forum/multisite/)
 * 2 replies
 * 2 participants
 * Last reply from: [msrebuildings](https://wordpress.org/support/users/msrebuildings/)
 * Last activity: [11 years, 7 months ago](https://wordpress.org/support/topic/delete-orphaned-users/#post-5331072)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
