While working on a project you may have had custom fields that are left behind and that are no longer in use for the current theme these unused custom fields remain in your database. I came across this exact scenario when I was upgrading a section of a website that was outdated and needed to be re-done. The previous programmer had use a plethora of custom fields and my goal was to reduce the amount of custom fields used.
Take a look at the following example. All the custom fields that are not being used
Removing Unused Custom Fields
- Log into to phpMyAdmin
- Select your database.
- If you use a different database prefix than the default “wp_” one, then you’ll need to change that in the example below. Replace “meta_key” with your actual custom field name.
- Run the following script. ( The script will run and delete any references to that custom field and the data associated with it )
DELETE FROM wp_postmeta WHERE meta_key = 'meta_key';
Alternatively you can also run an sql script that looks at meta_key and see if there are any empty values
SELECT * FROM wp_postmeta WHERE meta_key = 'meta_key';
In my scenario I needed to look for any custom field containing the words productOption running the sql script returned the following.
SELECT * FROM wp_postmeta WHERE meta_key LIKE '%productOption%';