B
B
badimint2018-08-04 10:58:15
MySQL
badimint, 2018-08-04 10:58:15

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'" );

But apparently, the prices are stored in another table and the query will be much more complicated.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Igor Vorotnev, 2018-08-09
@HeadOnFire

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 question

Ask a Question

731 491 924 answers to any question