SELECT SQL_CALC_FOUND_ROWS wp_posts.*
FROM wp_posts LEFT JOIN wp_term_relationships ON (wp_posts.ID = wp_term_relationships.object_id) INNER JOIN wp_postmeta ON ( wp_posts.ID = wp_postmeta.post_id ) LEFT JOIN wp_wc_product_meta_lookup wc_product_meta_lookup ON wp_posts.ID = wc_product_meta_lookup.product_id LEFT JOIN (SELECT * FROM wp_postmeta WHERE meta_key = '_sale_price' AND meta_value > 0) sale ON (wp_posts.ID = sale.post_id) LEFT JOIN (SELECT * FROM wp_postmeta WHERE meta_key = '_stock_status') stock ON (wp_posts.ID = stock.post_id)
WHERE 1=1 AND (
wp_posts.ID NOT IN (
SELECT object_id
FROM wp_term_relationships
WHERE term_taxonomy_id IN (7)
)
AND
wp_term_relationships.term_taxonomy_id IN (720)
) AND (
wp_postmeta.meta_key = '_price'
) AND ((wp_posts.post_type = 'product' AND (wp_posts.post_status = 'publish' OR wp_posts.post_status = 'acf-disabled' OR wp_posts.post_status = 'wc-fraud-screen' OR wp_posts.post_status = 'wc-authorised')))
GROUP BY wp_posts.ID
ORDER BY stock.meta_value ASC, sale.meta_value DESC, wc_product_meta_lookup.min_price ASC, wc_product_meta_lookup.product_id ASC
LIMIT 0, 1500