Answer the question
In order to leave comments, you need to log in
How to correctly compose a query in the Woocommrce database?
Good afternoon.
Could you please tell me how to correctly create a query in the database in order to update all the prices of goods that have the kyrs metafield filled in.
I'm trying to get through
$wpdb->get_results( "SELECT _price FROM `" . $wpdb->prefix . "posts` where post_type='product' and post_status = 'publish'" );
Answer the question
In order to leave comments, you need to log in
1. The _price field is in wp_postmeta, not wp_posts
2. The kyrs field (by the way, such a transliteration of the word "course" is an example of shit code) is also most likely in wp_postmeta
3. Do you need to set the same price for all products with the kyrs field?
4. In one request, this is not the fact that it is reasonable to form. First get the post IDs that post_type=product + post_status=publish + have a meta_key of 'kyrs'. And then work with this ID array, setting the desired prices in the wp_postmeta table.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question