{"id":9774,"date":"2026-06-07T14:48:50","date_gmt":"2026-06-07T12:48:50","guid":{"rendered":"https:\/\/mybox.com\/help\/?post_type=manual_kb&#038;p=9774"},"modified":"2026-06-07T14:48:51","modified_gmt":"2026-06-07T12:48:51","slug":"wordpress-optimization-removing-metadata-from-deleted-posts","status":"publish","type":"manual_kb","link":"https:\/\/mybox.com\/help\/en\/knowledgebase\/wordpress-optimization-removing-metadata-from-deleted-posts\/","title":{"rendered":"WordPress Optimization \u2013 Removing Metadata from Deleted Posts"},"content":{"rendered":"\n<div class=\"translation-block translation-block-merged\">\n<p class=\"wp-block-paragraph\">WordPress stores additional information related to posts, pages, and custom content types in a separate database table called <code>wp_postmeta<\/code>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">This table contains metadata used by:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>WordPress core features<\/li>\n\n\n\n<li>Themes<\/li>\n\n\n\n<li>Plugins<\/li>\n\n\n\n<li>Custom fields<\/li>\n\n\n\n<li>E-commerce extensions<\/li>\n\n\n\n<li>Page builders<\/li>\n<\/ul>\n\n\n\n<\/div>\n\n<div id=\"mybox-2793644177\" class=\"mybox-content mybox-entity-placement\"><div class=\"early-access-banner-inpost\">\r\n  <div class=\"banner-left-inpost\">\r\n    <div class=\"icon-box-inpost\">\r\n      <img decoding=\"async\" src=\"https:\/\/mybox.com\/help\/wp-content\/uploads\/2026\/02\/square-info-icon.svg\" alt=\"Info\">\r\n    <\/div>\r\n    <div class=\"text-box-inpost\">\r\n      <span class=\"label-inpost\"><span class=\"translation-block translation-block-banner-text\">Early access<\/span><\/span>\r\n      <h4><span class=\"translation-block translation-block-banner-text\">Still need help?<\/span><\/h4>\r\n      <p><span class=\"translation-block translation-block-banner-text\">Contact our customer service team.<\/span><\/p>\r\n    <\/div>\r\n  <\/div>\r\n\r\n  <div class=\"banner-right-inpost\">\r\n    <a href=\"https:\/\/panel.mybox.com\/helpdesk2\/v\/list\/\" class=\"banner-button-inpost\"><span class=\"translation-block translation-block-banner-text\">Message us<\/span><\/a>\r\n  <\/div>\r\n<\/div><\/div>\n\n<div class=\"translation-block translation-block-merged\"><p class=\"wp-block-paragraph\">When posts or pages are deleted, associated metadata may sometimes remain in the database. Over time, these orphaned records can accumulate and unnecessarily increase the size of the database.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">This guide explains how to identify and remove metadata entries that no longer belong to existing posts.<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p class=\"wp-block-paragraph\"><strong>Important<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">This guide is intended for users with basic database administration knowledge.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Before executing any SQL queries:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Create a complete database backup.<\/li>\n\n\n\n<li>Verify that you have selected the correct database.<\/li>\n\n\n\n<li>Test your website after performing any cleanup operations.<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">Removing data incorrectly may result in website functionality issues.<\/p>\n<\/blockquote>\n\n\n\n<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_86 ez-toc-wrap-left counter-hierarchy ez-toc-counter ez-toc-custom ez-toc-container-direction\">\n<div class=\"ez-toc-title-container\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">Table of Contents<\/p>\n<span class=\"ez-toc-title-toggle\"><\/span><\/div>\n<nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/mybox.com\/help\/en\/knowledgebase\/wordpress-optimization-removing-metadata-from-deleted-posts\/#Access_phpMyAdmin\" >Access phpMyAdmin<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/mybox.com\/help\/en\/knowledgebase\/wordpress-optimization-removing-metadata-from-deleted-posts\/#Log_In_to_the_Database\" >Log In to the Database<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/mybox.com\/help\/en\/knowledgebase\/wordpress-optimization-removing-metadata-from-deleted-posts\/#Open_the_SQL_Query_Editor\" >Open the SQL Query Editor<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/mybox.com\/help\/en\/knowledgebase\/wordpress-optimization-removing-metadata-from-deleted-posts\/#Remove_Orphaned_Metadata\" >Remove Orphaned Metadata<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/mybox.com\/help\/en\/knowledgebase\/wordpress-optimization-removing-metadata-from-deleted-posts\/#What_Does_This_Query_Do\" >What Does This Query Do?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/mybox.com\/help\/en\/knowledgebase\/wordpress-optimization-removing-metadata-from-deleted-posts\/#Benefits_of_Removing_Orphaned_Metadata\" >Benefits of Removing Orphaned Metadata<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-7\" href=\"https:\/\/mybox.com\/help\/en\/knowledgebase\/wordpress-optimization-removing-metadata-from-deleted-posts\/#Check_Before_Deleting_Optional\" >Check Before Deleting (Optional)<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-8\" href=\"https:\/\/mybox.com\/help\/en\/knowledgebase\/wordpress-optimization-removing-metadata-from-deleted-posts\/#Alternative_Cleanup_Methods\" >Alternative Cleanup Methods<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-9\" href=\"https:\/\/mybox.com\/help\/en\/knowledgebase\/wordpress-optimization-removing-metadata-from-deleted-posts\/#Summary\" >Summary<\/a><\/li><\/ul><\/nav><\/div>\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Access_phpMyAdmin\"><\/span>Access phpMyAdmin<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Log in to the mybox Panel.<\/li>\n\n\n\n<li>Navigate to:<\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code>Databases\n<\/code><\/pre>\n\n\n\n<ol start=\"3\" class=\"wp-block-list\">\n<li>Click:<\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code>phpMyAdmin\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">A new browser tab will open with the database login screen.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Log_In_to_the_Database\"><\/span>Log In to the Database<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Use the database credentials associated with your WordPress website.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">If you do not know the database credentials, you can find them in the <code>wp-config.php<\/code> file located in the root directory of your WordPress installation.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Example:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>define('DB_NAME', 'database_name');\ndefine('DB_USER', 'database_user');\ndefine('DB_PASSWORD', 'database_password');\ndefine('DB_HOST', 'database_host');\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The file is typically located in:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>public_html\n<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Open_the_SQL_Query_Editor\"><\/span>Open the SQL Query Editor<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">After logging in:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Select your WordPress database from the left-hand menu.<\/li>\n\n\n\n<li>Click the:<\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code>SQL\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">tab at the top of the page.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">This will open the query editor.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Remove_Orphaned_Metadata\"><\/span>Remove Orphaned Metadata<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Enter the following SQL query:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>DELETE pm\nFROM wp_postmeta pm\nLEFT JOIN wp_posts wp ON wp.ID = pm.post_id\nWHERE wp.ID IS NULL;\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Click:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Execute\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">to run the query.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"What_Does_This_Query_Do\"><\/span>What Does This Query Do?<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">The query searches for entries in the <code>wp_postmeta<\/code> table whose associated post no longer exists in the <code>wp_posts<\/code> table.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">These records are considered orphaned metadata.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The query removes metadata linked to:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Deleted posts<\/li>\n\n\n\n<li>Deleted pages<\/li>\n\n\n\n<li>Deleted custom post types<\/li>\n\n\n\n<li>Content removed by plugins<\/li>\n\n\n\n<li>Other non-existent WordPress content<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Benefits_of_Removing_Orphaned_Metadata\"><\/span>Benefits of Removing Orphaned Metadata<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Cleaning unused metadata can provide several benefits:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Reduced database size.<\/li>\n\n\n\n<li>Faster database backups.<\/li>\n\n\n\n<li>Improved query performance.<\/li>\n\n\n\n<li>Reduced storage consumption.<\/li>\n\n\n\n<li>Better overall WordPress performance.<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">The impact is especially noticeable on websites that:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Have been running for a long time.<\/li>\n\n\n\n<li>Frequently delete or update content.<\/li>\n\n\n\n<li>Use many plugins.<\/li>\n\n\n\n<li>Have imported or migrated content multiple times.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Check_Before_Deleting_Optional\"><\/span>Check Before Deleting (Optional)<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">If you want to review the records before deleting them, run:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>SELECT pm.*\nFROM wp_postmeta pm\nLEFT JOIN wp_posts wp ON wp.ID = pm.post_id\nWHERE wp.ID IS NULL;\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">This query displays the orphaned metadata without removing it.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">After reviewing the results, you can decide whether to proceed with the cleanup.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Alternative_Cleanup_Methods\"><\/span>Alternative Cleanup Methods<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">If you prefer not to execute SQL commands manually, several WordPress optimization plugins can perform this cleanup automatically, including:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>WP-Optimize<\/li>\n\n\n\n<li>Advanced Database Cleaner<\/li>\n\n\n\n<li>LiteSpeed Cache<\/li>\n\n\n\n<li>WP Rocket<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">These plugins can identify and remove orphaned metadata directly from the WordPress dashboard.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Summary\"><\/span>Summary<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Over time, WordPress may accumulate metadata entries associated with posts that no longer exist. These orphaned records occupy space and can contribute to database bloat.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">To remove them:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Open phpMyAdmin.<\/li>\n\n\n\n<li>Select your WordPress database.<\/li>\n\n\n\n<li>Open the SQL tab.<\/li>\n\n\n\n<li>Execute:<\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code>DELETE pm\nFROM wp_postmeta pm\nLEFT JOIN wp_posts wp ON wp.ID = pm.post_id\nWHERE wp.ID IS NULL;\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Always create a database backup before performing cleanup operations and verify that your website functions correctly afterward.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n<\/div>\n","protected":false},"author":1,"featured_media":0,"parent":0,"menu_order":0,"template":"","format":"standard","manualknowledgebasecat":[58],"manual_kb_tag":[389,2146,2147,2750,4835,4836,4837,4838,4839,190],"class_list":["post-9774","manual_kb","type-manual_kb","status-publish","format-standard","hentry","manualknowledgebasecat-web-applications-cms","manual_kb_tag-database-backup","manual_kb_tag-phpmyadmin","manual_kb_tag-database-optimization","manual_kb_tag-database-cleanup","manual_kb_tag-wp-postmeta","manual_kb_tag-wp-posts","manual_kb_tag-orphaned-metadata","manual_kb_tag-remove-orphaned-metadata","manual_kb_tag-postmeta-cleanup","manual_kb_tag-wordpress"],"_links":{"self":[{"href":"https:\/\/mybox.com\/help\/en\/wp-json\/wp\/v2\/manual_kb\/9774","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/mybox.com\/help\/en\/wp-json\/wp\/v2\/manual_kb"}],"about":[{"href":"https:\/\/mybox.com\/help\/en\/wp-json\/wp\/v2\/types\/manual_kb"}],"author":[{"embeddable":true,"href":"https:\/\/mybox.com\/help\/en\/wp-json\/wp\/v2\/users\/1"}],"version-history":[{"count":1,"href":"https:\/\/mybox.com\/help\/en\/wp-json\/wp\/v2\/manual_kb\/9774\/revisions"}],"predecessor-version":[{"id":9775,"href":"https:\/\/mybox.com\/help\/en\/wp-json\/wp\/v2\/manual_kb\/9774\/revisions\/9775"}],"wp:attachment":[{"href":"https:\/\/mybox.com\/help\/en\/wp-json\/wp\/v2\/media?parent=9774"}],"wp:term":[{"taxonomy":"manualknowledgebasecat","embeddable":true,"href":"https:\/\/mybox.com\/help\/en\/wp-json\/wp\/v2\/manualknowledgebasecat?post=9774"},{"taxonomy":"manual_kb_tag","embeddable":true,"href":"https:\/\/mybox.com\/help\/en\/wp-json\/wp\/v2\/manual_kb_tag?post=9774"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}