Skip to content

Instantly share code, notes, and snippets.

@decodist
Last active December 2, 2020 16:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save decodist/10e548a5ea915381f5b3b1062cd3ed1f to your computer and use it in GitHub Desktop.
Save decodist/10e548a5ea915381f5b3b1062cd3ed1f to your computer and use it in GitHub Desktop.
Find Wordpress users who have logged in at some point, but not within the past year
SELECT u.id, u.user_login, u.user_email, u.user_registered,
from_unixtime(
trim( trailing ';}}' from
RIGHT(
um.meta_value,
(LENGTH(um.meta_value) - LOCATE('login',um.meta_value) - 8)
)
)
,'%Y-%m-%d') as last_login
FROM wp_users u, wp_usermeta um
WHERE um.user_id = u.id
AND um.meta_key = 'session_tokens'
HAVING last_login < DATE_SUB(NOW(),INTERVAL 1 YEAR)
ORDER BY last_login DESC
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment