Skip to content

Instantly share code, notes, and snippets.

@carlosleopoldo
Last active September 22, 2024 09:06
Show Gist options
  • Save carlosleopoldo/5897807 to your computer and use it in GitHub Desktop.
Save carlosleopoldo/5897807 to your computer and use it in GitHub Desktop.
Delete all orphans user meta in WordPress
DELETE FROM wp_usermeta
WHERE NOT EXISTS (
SELECT * FROM wp_users
WHERE wp_usermeta.user_id = wp_users.ID
)
@zoxee
Copy link

zoxee commented May 17, 2017

Excellent

@SteenSchutt
Copy link

Thanks - helped me get rid of 900k rows of usermeta after removing customers from a Woocommerce site for export 👍

@zubaer-ahammed
Copy link

This is very useful. Thank you @carlosleopoldo

@KhalilAhmadDanish
Copy link

It was Great! worked for me.

@dragosstancu
Copy link

Bravo!

@dragosstancu
Copy link

Found a shorter one:

DELETE FROM wp_usermeta WHERE user_id NOT IN (SELECT ID FROM wp_users);

@ahmadawais
Copy link

Deleted my admin user for some reason. Dev site so I'm safe.

@sepidev
Copy link

sepidev commented Sep 22, 2024

nice

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment