-- Ref. https://www.facebook.com/groups/advanced.woocommerce/permalink/1339363232744759/ SELECT posts.ID FROM posts INNER JOIN term_relationships ON (posts.ID = term_relationships.object_id) INNER JOIN postmeta ON ( posts.ID = postmeta.post_id ) INNER JOIN postmeta AS mt1 ON ( posts.ID = mt1.post_id ) WHERE (term_relationships.term_taxonomy_id IN (2365,2366,2367,2374,2375,2376,2385,2386) ) AND (postmeta.meta_key = '_price' AND ( ( mt1.meta_key = '_visibility' AND mt1.meta_value IN ('visible','catalog') ) ) ) AND posts.post_type = 'product' AND (posts.post_status = 'publish' OR posts.post_status = 'private') ORDER BY postmeta.meta_value DESC, posts.ID DESC LIMIT 0, 10;