복붙노트

[WORDPRESS] 제품 유형별로 쿼리 / 필터 제품 WooCommerce 제품

WORDPRESS

제품 유형별로 쿼리 / 필터 제품 WooCommerce 제품

해결법


  1. 1.WOOCOMMERCE에서 "POST TYPE"은 사용자 정의 분류법이므로 WP_QUERY에 분류 된 매개 변수를 추가해야합니다.

    WOOCOMMERCE에서 "POST TYPE"은 사용자 정의 분류법이므로 WP_QUERY에 분류 된 매개 변수를 추가해야합니다.

    $query_args = array(
       'post_type' => 'product',
       'tax_query' => array(
            array(
                'taxonomy' => 'product_type',
                'field'    => 'slug',
                'terms'    => 'your_type', 
            ),
        ),
     );
    

    인수는 $ this-> product_type = 'your_type'에서와 동일한 곳입니다. 새 제품 유형의 클래스 생성자의 일부입니다.


  2. 2.깨끗한 방법 - WP_QUERY가 아닌 WOOCOMMERCE WC_GET_PODUCTS를 사용하십시오.

    깨끗한 방법 - WP_QUERY가 아닌 WOOCOMMERCE WC_GET_PODUCTS를 사용하십시오.

    $args = array(
        'type' => 'custom_product_type'
        );
    $products = wc_get_products( $args );
    
  3. from https://stackoverflow.com/questions/29804963/query-filter-woocommerce-products-by-product-type by cc-by-sa and MIT license