Created
July 11, 2014 14:14
-
-
Save pelmered/20718fd4162be0df32d7 to your computer and use it in GitHub Desktop.
Stackoverflow #24573343
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$product_ids_raw = $wpdb->get_results( | |
"SELECT wp_posts.ID, wp_posts.post_parent | |
FROM wp_posts | |
INNER JOIN wp_postmeta ON (wp_posts.ID = wp_postmeta.post_id) | |
INNER JOIN wp_postmeta AS mt1 ON (wp_posts.ID = mt1.post_id) | |
WHERE | |
wp_posts.post_status = 'publish' | |
AND (mt1.meta_key = '_sale_price_dates_to' AND mt1.meta_value >= ".time().") | |
GROUP BY wp_posts.ID | |
ORDER BY wp_posts.post_title ASC LIMIT 0,12"); | |
$product_ids_on_sale = array(); | |
foreach ( $product_ids_raw as $product_raw ) | |
{ | |
if(!empty($product_raw->post_parent)) | |
{ | |
if(!in_array($product_raw->post_parent, $product_ids_on_sale)) | |
{ | |
$product_ids_on_sale[] = $product_raw->post_parent; | |
} | |
} | |
else | |
{ | |
$product_ids_on_sale[] = $product_raw->ID; | |
} | |
} | |
$meta_query = array(); | |
$meta_query[] = WC()->query->visibility_meta_query(); | |
$meta_query[] = WC()->query->stock_status_meta_query(); | |
$meta_query = array_filter( $meta_query ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment