Optimise wp_postmeta table and remove custom fields meta keys

Overtime a wp_postmeta WordPress database table may become bloated and use redundant custom field meta_keys. The table may have thousands of rows worth of dead data such as old custom fields.

You can remove these keys quite quickly in the MySQL database once you know the key format, I recently took over a site that previously used Avada Theme but now had no more use for it – it had 10s of 1,000s of rows ready for culling. Avada custom fields use the meta key ‘pyre_’

Best way to remove these rows is to to a select first to see then do a delete – but first do a back up.

remove-post-meta-keys

Select Meta Keys

SELECT * FROM `wp_postmeta` WHERE meta_key LIKE '%pyre_%';

Delete Meta Keys

DELETE FROM `wp_postmeta` WHERE meta_key LIKE '%pyre_%';

That’s it now your database should lose a bit of bloat.

Once you know how the meta keys are named it is easy, there is also a plugin that you can select the custom fields from a dropdown and remove them, it’s called Delete Custom Fields  and works in the latest version of WordPress.

Another WordPress that you can optimise is the wp_options table, this post looks at removing data from the table in particular autoload options which appear on every WordPress post/page load.

2 comments

  • How would you even know what meta data to look for? That’s what I’d love to know. Like how would you even start to know that this meta key value is bloating the site?

    I have a table postmeta that has 9M rows in it. It should only have 1M but every time GoDaddy restarted the server it duplicated that table. I need to figure a way to decrease this table with rows.

    Thanks

  • Thank you that’s neat

Leave your comment