• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar

WP Bitz

A curated collection of code snippets for WordPress

  • Home
  • About
  • Blog
  • Code Snippets
You are here: Home / WordPress Development Tips / Check and delete orphaned user meta in WordPress

Check and delete orphaned user meta in WordPress

WordPress Development Tips · November 28, 2025

This post brought to you by RocketGeek, ButlerBlog, and the following:

 

Through the natural course of managing a WordPress site and its database, you may end up with some orphaned user meta entries in the database. “Orphaned” data is a value that belongs to a related ID (in this case, user) that not longer exists in the related table. This is especially true if you run any delete queries on the posts table directly in MySQL, or if you do a lot of plugin/custom code development and/or testing.

The following MySQL queries can help you check for and delete any orphaned user meta entries. These are entries that exist in the wp_usermeta table for which no associated user ID exists in the wp_users table.

IMPORTANT: be sure to backup your database before running any direct MySQL queries – especially those that delete data.

Get a list of orphaned user meta

SELECT * FROM rg_usermeta um
LEFT JOIN rg_users u ON u.ID = um.user_id
WHERE u.ID IS NULL

Delete orphaned user meta

DELETE um
FROM wp_usermeta um
LEFT JOIN wp_posts u ON wp.ID = um.user_id
WHERE u.ID IS NULL

Filed Under: WordPress Development Tips

Chad Butler

This post brought to you by RocketGeek, ButlerBlog, and the following:

 

Reader Interactions

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Primary Sidebar

Join for free!

Get free code snippets, WordPress best practices, and practical Content Marketing advice from seasoned WordPress expert Chad Butler (butlerblog):

Recent Posts

  • Check and delete orphaned user meta in WordPress
  • Add a Database Connection to use WPDB
  • Notice: Function WP_Block_Patterns_Registry::register was called incorrectly
  • Use WP-CLI to back up your site
  • Bitnami WordPress Autoptimize cannot write to the cache directory

Copyright © 2026 · Maker Pro on Genesis Framework · WordPress · Log in