Skip to content
Advertisement

If a meta_key has a meta_value, update the meta_key name

In a table called wp_postmeta, there are ~1K meta_key‘s called _wcj_custom_product_tabs_content_local_1, but only ~100 have a meta_value.

What I need to do is update the meta_key name, but only for the meta_key‘s that actually have a meta_value.

I can select all the meta_key‘s that are not empty with this:

But then how do I combine the query above with the update query below so only the not empty meta_keys selected have their names updated?

Advertisement

Answer

Taking the WHERE clauses from your SELECT query, and prepending the UPDATE statement gives you the following query:

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement