I have a meta attribute on my products that can be accessed like this:
get_post_meta( $product_id, '_disable_shipping', true );
I need to update _disable_shipping
attribute of all products on MySQL or programmatically. Is there a simple way of doing it? I want to change all values to yes
for all my products.
2
Answers
You can create a plugin and put a function in it which runs through your products and updates every products meta value. If you don’t know how you create a plugin, here is a tutorial for this: https://www.smashingmagazine.com/2011/09/how-to-create-a-wordpress-plugin/ It is done in minutes.
Please make sure you have a backup of your database before doing bulk actions to update your products.
The function could look something like this:
If you activate your plugin, this function will run. After that, you can deactivate it again.
This code should be pretty save, because it only updates post meta, if the value is “no”, so there should not be any unintended updates of the posts.
Maybe there also is a plugin for bulk editing your products. This is the first I found which seems to be doing the job, haven’t tested it yet: https://wordpress.org/plugins/custom-field-bulk-editor/
You can use the following MYSQL query ,
wp_postmeta
depends on your wordpress database prefix