Please I just migrated my site and I found out that wp_postmeta consumes most of my cpu resources, Is the any Sql code to Delete all post meta except the featured image. I dont want to Use wp functions for this. Just need only phpmyadmin sql code. I have read this similar Post, But I need the sql code for it, not functions
-
Are you sure you want to do this? There can be a lot of important stuff in meta.– Jacob PeattieJul 28, 2018 at 3:59
-
Yes, I really want to do this– Godwin Alex OgbondaJul 28, 2018 at 4:02
1 Answer
I rewrote the function from the link in your question to SQL.
Keep in mind that this script will also clear the page-templates assigned to the pages.
Make a backup of the wp_postmeta
table first.
DELETE pm
FROM wp_postmeta pm LEFT JOIN wp_posts p ON pm.post_id = p.id
WHERE
(p.post_type IN ('post', 'page') AND pm.meta_key <> '_thumbnail_id')
OR (p.post_type = 'attachment' AND pm.meta_key <> '_wp_attached_file'
AND pm.meta_key <> '_wp_attachment_metadata')