0

The site I am working on used to keep some data in posts meta. It is a WooCommerce site and the data was kept in products variations and fields names look like _field_name[12345] where 12345 is a variation id.

That caused bloating of import/export files and creating a lot of rows in the database and the meta fields which keep this data now look like __field_name.

Now I am looking for a simple (which will not take long to implement) solution to remove the fields like _field_name[12345] from all the variations.

However, there are quite a lot of products on the site and just looping through all the products, each variation of each product and make delete_post_meta($variation_id) is not an option because we will run out of memory or time limit. Making an AJAX-based function which will break queries with a timeout does not fit the simple solution criteria.

Can you please give me another idea of cleaning this mess?

0

Sometimes one just needs to ask to understand what the issue is.

DELETE FROM 
`db_name`.`wp_postmeta`  
WHERE `wp_postmeta`. `meta_key` LIKE  '_field_name[%]'

did the trick.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.