Fixed meta_query for shortcodes, closes #6960

This commit is contained in:
Claudio Sanches 2014-12-21 13:31:27 -02:00
parent a79bedc945
commit 389a829474
1 changed files with 41 additions and 74 deletions

View File

@ -140,6 +140,7 @@ class WC_Shortcodes {
// Default ordering args // Default ordering args
$ordering_args = WC()->query->get_catalog_ordering_args( $atts['orderby'], $atts['order'] ); $ordering_args = WC()->query->get_catalog_ordering_args( $atts['orderby'], $atts['order'] );
$meta_query = WC()->query->get_meta_query();
$args = array( $args = array(
'post_type' => 'product', 'post_type' => 'product',
@ -148,13 +149,7 @@ class WC_Shortcodes {
'orderby' => $ordering_args['orderby'], 'orderby' => $ordering_args['orderby'],
'order' => $ordering_args['order'], 'order' => $ordering_args['order'],
'posts_per_page' => $atts['per_page'], 'posts_per_page' => $atts['per_page'],
'meta_query' => array( 'meta_query' => $meta_query,
array(
'key' => '_visibility',
'value' => array('catalog', 'visible'),
'compare' => 'IN'
)
),
'tax_query' => array( 'tax_query' => array(
array( array(
'taxonomy' => 'product_cat', 'taxonomy' => 'product_cat',
@ -357,20 +352,16 @@ class WC_Shortcodes {
'order' => 'asc' 'order' => 'asc'
), $atts ); ), $atts );
$meta_query = WC()->query->get_meta_query();
$args = array( $args = array(
'post_type' => 'product', 'post_type' => 'product',
'post_status' => 'publish', 'post_status' => 'publish',
'ignore_sticky_posts' => 1, 'ignore_sticky_posts' => 1,
'orderby' => $atts['orderby'], 'orderby' => $atts['orderby'],
'order' => $atts['order'], 'order' => $atts['order'],
'posts_per_page' => -1, 'posts_per_page' => -1,
'meta_query' => array( 'meta_query' => $meta_query
array(
'key' => '_visibility',
'value' => array('catalog', 'visible'),
'compare' => 'IN'
)
)
); );
if ( isset( $atts['skus'] ) ) { if ( isset( $atts['skus'] ) ) {
@ -426,18 +417,14 @@ class WC_Shortcodes {
return ''; return '';
} }
$meta_query = WC()->query->get_meta_query();
$args = array( $args = array(
'post_type' => 'product', 'post_type' => 'product',
'posts_per_page' => 1, 'posts_per_page' => 1,
'no_found_rows' => 1, 'no_found_rows' => 1,
'post_status' => 'publish', 'post_status' => 'publish',
'meta_query' => array( 'meta_query' => $meta_query
array(
'key' => '_visibility',
'value' => array('catalog', 'visible'),
'compare' => 'IN'
)
)
); );
if ( isset( $atts['sku'] ) ) { if ( isset( $atts['sku'] ) ) {
@ -580,10 +567,7 @@ class WC_Shortcodes {
// Get products on sale // Get products on sale
$product_ids_on_sale = wc_get_product_ids_on_sale(); $product_ids_on_sale = wc_get_product_ids_on_sale();
$meta_query = array(); $meta_query = WC()->query->get_meta_query();
$meta_query[] = WC()->query->visibility_meta_query();
$meta_query[] = WC()->query->stock_status_meta_query();
$meta_query = array_filter( $meta_query );
$args = array( $args = array(
'posts_per_page' => $atts['per_page'], 'posts_per_page' => $atts['per_page'],
@ -635,6 +619,8 @@ class WC_Shortcodes {
'columns' => '4' 'columns' => '4'
), $atts ); ), $atts );
$meta_query = WC()->query->get_meta_query();
$args = array( $args = array(
'post_type' => 'product', 'post_type' => 'product',
'post_status' => 'publish', 'post_status' => 'publish',
@ -642,13 +628,7 @@ class WC_Shortcodes {
'posts_per_page' => $atts['per_page'], 'posts_per_page' => $atts['per_page'],
'meta_key' => 'total_sales', 'meta_key' => 'total_sales',
'orderby' => 'meta_value_num', 'orderby' => 'meta_value_num',
'meta_query' => array( 'meta_query' => $meta_query
array(
'key' => '_visibility',
'value' => array( 'catalog', 'visible' ),
'compare' => 'IN'
)
)
); );
ob_start(); ob_start();
@ -692,20 +672,16 @@ class WC_Shortcodes {
'order' => 'asc' 'order' => 'asc'
), $atts ); ), $atts );
$meta_query = WC()->query->get_meta_query();
$args = array( $args = array(
'post_type' => 'product', 'post_type' => 'product',
'post_status' => 'publish', 'post_status' => 'publish',
'ignore_sticky_posts' => 1, 'ignore_sticky_posts' => 1,
'orderby' => $atts['orderby'], 'orderby' => $atts['orderby'],
'order' => $atts['order'], 'order' => $atts['order'],
'posts_per_page' => $atts['per_page'], 'posts_per_page' => $atts['per_page'],
'meta_query' => array( 'meta_query' => $meta_query
array(
'key' => '_visibility',
'value' => array('catalog', 'visible'),
'compare' => 'IN'
)
)
); );
ob_start(); ob_start();
@ -753,6 +729,12 @@ class WC_Shortcodes {
'order' => 'desc' 'order' => 'desc'
), $atts ); ), $atts );
$meta_query = WC()->query->get_meta_query();
$meta_query[] = array(
'key' => '_featured',
'value' => 'yes'
);
$args = array( $args = array(
'post_type' => 'product', 'post_type' => 'product',
'post_status' => 'publish', 'post_status' => 'publish',
@ -760,17 +742,7 @@ class WC_Shortcodes {
'posts_per_page' => $atts['per_page'], 'posts_per_page' => $atts['per_page'],
'orderby' => $atts['orderby'], 'orderby' => $atts['orderby'],
'order' => $atts['order'], 'order' => $atts['order'],
'meta_query' => array( 'meta_query' => $meta_query
array(
'key' => '_visibility',
'value' => array('catalog', 'visible'),
'compare' => 'IN'
),
array(
'key' => '_featured',
'value' => 'yes'
)
)
); );
ob_start(); ob_start();
@ -910,7 +882,8 @@ class WC_Shortcodes {
'filter' => '' 'filter' => ''
), $atts ); ), $atts );
$attribute = strstr( $atts['attribute'], 'pa_' ) ? sanitize_title( $atts['attribute'] ) : 'pa_' . sanitize_title( $atts['attribute'] ); $attribute = strstr( $atts['attribute'], 'pa_' ) ? sanitize_title( $atts['attribute'] ) : 'pa_' . sanitize_title( $atts['attribute'] );
$meta_query = WC()->query->get_meta_query();
$args = array( $args = array(
'post_type' => 'product', 'post_type' => 'product',
@ -919,13 +892,7 @@ class WC_Shortcodes {
'posts_per_page' => $atts['per_page'], 'posts_per_page' => $atts['per_page'],
'orderby' => $atts['orderby'], 'orderby' => $atts['orderby'],
'order' => $atts['order'], 'order' => $atts['order'],
'meta_query' => array( 'meta_query' => $meta_query,
array(
'key' => '_visibility',
'value' => array('catalog', 'visible'),
'compare' => 'IN'
)
),
'tax_query' => array( 'tax_query' => array(
array( array(
'taxonomy' => $attribute, 'taxonomy' => $attribute,