I'm using woocommerce and offer for woocommerce. And I want to get the products IDs without offers. I prepared the code but it doesn't work :( I tried in the second query: SELECT distinct(wp_postmeta.meta_value) ..., but it doesn't work, too.
$draftid = $wpdb->get_col('SELECT wp_posts.ID FROM ' . $wpdb->postmeta . ' join ' . $wpdb->posts . ' ON wp_posts.ID = wp_postmeta.post_id
WHERE wp_posts.post_status="draft" and wp_postmeta.meta_key="_sale_price_dates_to" and wp_postmeta.meta_value != "" and wp_postmeta.meta_value<="' . (time()-1296000) . '"
EXCEPT SELECT wp_postmeta.meta_value FROM ' . $wpdb->postmeta . ' join ' . $wpdb->posts . ' ON wp_posts.ID = wp_postmeta.post_id
WHERE wp_postmeta.meta_key="orig_offer_product_id" and wp_postmeta.meta_value !="" and wp_posts.post_type="woocommerce_offer"'); print_r($draftid);
But separately the first query works, and the second too. If I use 'union' instead of 'except', it works too.
Any idea why?
Try the following without any guaranty:
I hope it will work.