SQL query to delete metadata of a custom post type, not the post
-
I posted this question on StackExchange but not getting answers, hoping someone here can help…..
I have a custom post type with a metakey/value associated for which I need to delete the metadata, but not the post itself.
This is further complicated by the fact that 2 other post types (‘post’ and 2 other CPTs) also have this same metakey/value pair, and I don’t want to delete the metadata associated with those other post types, just one particular post type……so I can’t just clean this metadata out of the wp_postmeta table without specifying which post type to isolate.
My SQL skills are not good enough yet to do this without a mistake (although I do have my DB backed up), I would be very grateful for any help.
Custom post type is ‘deal’.
Metakey is ‘resort_chain’.Background if anyone is interested or would find it helpful: We setup a CPT with custom fields using ACF Pro, but found (after entering many hundreds of ‘deals’) that we were entering a lot of data that is better associated with the ‘resort’ and the ‘deal’ entry could be made much faster and more efficient by setting up another CPT (‘resort’) and associating a lot of the metadata with the Resort – that way many deals can be entered for each resort without repetitively entering resort information. That data is now associated to the Deal via a (ACF) ‘relationship’ field.
BUT I need to clean out the data that is still attached to the Deal(s) so that I can properly test the search/filter function as well as the template display.
I just want to be sure that I remove that data only from Deals posts and not from Resorts posts or our other custom post type (‘faqs’) – both of which do contain a lot of the same metadata.
- The topic ‘SQL query to delete metadata of a custom post type, not the post’ is closed to new replies.