2014-09-04 30 views
0

我有一個WordPress站點使用woocommerce。WordPress的Woocommerce試圖過濾僅在特定類別的銷售項目

我正在嘗試使用過濾器產品使用WP_query來顯示只有在出售,並且哪些也只在某一類別的4個產品。

我正在使用meta_query僅在銷售產品中進行過濾,而在tax_query中過濾此類別。

我很努力讓循環工作使用tax_query和meta_query,雖然其中任何一個沒有其他工作正常。

(我也嘗試在參數中使用'product_cateogory'=>'skateboard-footwear',但結果是一樣的)。

下面的代碼:

$args = array( 
         'post_type' => 'product', 
         'orderby'  => 'date', 
         'order'  => 'desc', 
         'posts_per_page' => '4', 
         'meta_query' => array(
         array(
          'key'  => '_sale_price', 
          'value' => 0, 
          'compare' => '>', 
          'type' => 'numeric' 
         ) 
         ), 
         'tax_query' => array(
         array(
          'taxonomy' => 'product_cat', 
          'field'  => 'slug', 
          'terms'  => 'skateboard-footwear', 
          'operator' => 'IN' 
          ) 
         ) 
        ); 


       $the_query = new WP_Query($args); 
       while ($the_query->have_posts()) : $the_query->the_post(); ?> 

回答

0
  $args = array( 
        'post_type' => 'product', 
        'orderby'  => 'date', 
        'order'  => 'desc', 
        'posts_per_page' => '4', 
        'meta_query' => array(
        array(
         'key'  => '_sale_price', 
         'value' => 0, 
         'compare' => '>', 
         'type' => 'numeric' 
        ) 
        ), 
    array(// Variable products type 
     'key'   => '_min_variation_sale_price', 
     'value'   => 0, 
     'compare'  => '>', 
     'type'   => 'numeric' 
    ), 
        'tax_query' => array(
        array(
         'taxonomy' => 'product_cat', 
         'field'  => 'id', 
         'terms'  => '27', 
         'operator' => 'IN' 
         ) 
        ) 
       ); 

需要增加一個陣列,多數民衆贊成指定分鐘變化銷售價格,然後使用後tax_query。還可以通過其ID使用產品類別。

相關問題