Last active
August 8, 2024 10:14
-
-
Save adeel-raza/45530060dc9b0deb2d0c65d850ffb5c8 to your computer and use it in GitHub Desktop.
Delete all users on a WordPress site who haven't logged in for one year
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Step 1: Delete from wp_usermeta | |
DELETE FROM wp_usermeta | |
WHERE user_id IN ( | |
SELECT ID | |
FROM wp_users | |
WHERE ID IN ( | |
SELECT user_id | |
FROM wp_usermeta | |
WHERE meta_key = 'last_login' | |
AND FROM_UNIXTIME(meta_value) < DATE_SUB(NOW(), INTERVAL 1 YEAR) | |
) | |
); | |
-- Step 2: Delete from wp_users | |
DELETE FROM wp_users | |
WHERE ID IN ( | |
SELECT user_id | |
FROM wp_usermeta | |
WHERE meta_key = 'last_login' | |
AND FROM_UNIXTIME(meta_value) < DATE_SUB(NOW(), INTERVAL 1 YEAR) | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
First try it on a staging site dont directly use on production. You can run this MySQL query from your PHPMyadmin area in your database management on the hosting. This should remove the ones who haven't logged in for a year via the INTERVAL 1 YEAR Command in the query yiu can adjust it according to your requirement.