2014-09-04 4 views
0

woocommerce를 사용하여 WordPress 사이트가 있습니다.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로 제품 범주를 사용하십시오.