After modifying how certain metadata works with Posts, I’ve decided to delete a field group that is now no longer needed.
BUT a number of posts still have that metadata associated.
Just as a matter of hygiene, I’d like to remove that meta key and values from those posts, but I do not have the SQL skills to write the query myself. I DO have access via phpMyAdmin, and am skilled enough to use it (always carefully and after backing up first!), but I could use some help in writing the query that will search the wp_postmeta table, find those Posts that have that metakey, and delete the key and it’s value.
Anyone good with SQL queries?
Thanks in advance for any help!
🙂
Hi @trisham
I believe you can do it like this:
DELETE FROM wp_postmeta WHERE wp_postmeta.meta_key = "custom_field_name" OR wp_postmeta.meta_key = "_custom_field_name"
If you have time, please learn more about SQL here: http://www.w3schools.com/sql/.
Thanks!
Thanks @James!
That worked perfectly, and thank you for the link – I do try to learn more all the time, but for some reason SQL queries still make me a bit nervous, although I do always backup my DB first.
Your help is much appreciated 🙂
Why don’t you add this feature to the plugin itself, when someone removes any custom field from the group, please try storing them in a list and then either you can add an option to allow deleting them from DB, or we will at least have key and can delete them all in a run. Sometimes we do it in a hurry and lots of the fields remain there for lifetime, so we should have at least some option.
Yes why is this not something to add to the plugin? I deleted a content item from a repeater, but it’s still showing on the frontend, it hasn’t been removed from the database. How do I solve this??
Respectfully I echo er.mayankrajput’s suggestion for consideration in a future update…..an option to delete – or not – the data already stored in the DB that is associated with the field (or repeater row) being deleted.