Meta_queries Closes #2182.

This commit is contained in:
Mike Jolley 2013-01-10 16:02:04 +00:00
parent 349308ccdb
commit 1766f07c19
3 changed files with 29 additions and 21 deletions

View File

@ -325,6 +325,10 @@ class WC_Shortcodes {
'order' => 'desc'
), $atts));
$meta_query = array();
$meta_query[] = $woocommerce->query->visibility_meta_query();
$meta_query[] = $woocommerce->query->stock_status_meta_query();
$args = array(
'post_type' => 'product',
'post_status' => 'publish',
@ -332,13 +336,7 @@ class WC_Shortcodes {
'posts_per_page' => $per_page,
'orderby' => $orderby,
'order' => $order,
'meta_query' => array(
array(
'key' => '_visibility',
'value' => array('catalog', 'visible'),
'compare' => 'IN'
)
)
'meta_query' => $meta_query
);
ob_start();

View File

@ -15,13 +15,18 @@ $crosssells = $woocommerce->cart->get_cross_sells();
if ( sizeof( $crosssells ) == 0 ) return;
$meta_query = array();
$meta_query[] = $woocommerce->query->visibility_meta_query();
$meta_query[] = $woocommerce->query->stock_status_meta_query();
$args = array(
'post_type' => 'product',
'ignore_sticky_posts' => 1,
'posts_per_page' => 2,
'no_found_rows' => 1,
'orderby' => 'rand',
'post__in' => $crosssells
'post_type' => 'product',
'ignore_sticky_posts' => 1,
'posts_per_page' => 2,
'no_found_rows' => 1,
'orderby' => 'rand',
'post__in' => $crosssells,
'meta_query' => $meta_query
);
$products = new WP_Query( $args );

View File

@ -9,20 +9,25 @@
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
global $product, $woocommerce_loop;
global $product, $woocommerce, $woocommerce_loop;
$upsells = $product->get_upsells();
if ( sizeof( $upsells ) == 0 ) return;
$meta_query = array();
$meta_query[] = $woocommerce->query->visibility_meta_query();
$meta_query[] = $woocommerce->query->stock_status_meta_query();
$args = array(
'post_type' => 'product',
'ignore_sticky_posts' => 1,
'no_found_rows' => 1,
'posts_per_page' => $posts_per_page,
'orderby' => $orderby,
'post__in' => $upsells,
'post__not_in' => array($product->id)
'post_type' => 'product',
'ignore_sticky_posts' => 1,
'no_found_rows' => 1,
'posts_per_page' => $posts_per_page,
'orderby' => $orderby,
'post__in' => $upsells,
'post__not_in' => array( $product->id ),
'meta_query' => $meta_query
);
$products = new WP_Query( $args );