• Resolved pm4698

    (@pm4698)


    I use a plugin that loops in products that are not in specific categories. I want to modify this plugin to include specific product ids.

    Current query:

    $query = new WC_Product_Query(
                array(
                'status' => array('publish'), 
                'limit' => 300,
                'paginate' => true,
                'page' => $i
            ));
            if(count($cats_excluded) > 0) {
                $query->set('tax_query', array(
                    array(
                    'taxonomy' => 'product_cat',
                    'field'    => 'term_id',
                    'terms'    => $cats_excluded,
                    'operator' => ('NOT IN'),
                    )));
            }

    What i am trying to do:

    $query = new WC_Product_Query(
                array(
                'status' => array('publish'), 
                'limit' => 300,
                'paginate' => true,
                'page' => $i
            ));
            if(count($cats_excluded) > 0) {
                $query->set('tax_query', array(
                    'relation' => 'AND',
                    array(
                    'taxonomy' => 'product_cat',
                    'field'    => 'term_id',
                    'terms'    => $cats_excluded,
                    'operator' => ('NOT IN'),
                    ),
                    array(
                    'taxonomy' => 'product',
                    'field' => $product_id,
                    'terms' => $products_included,
                    'operator' => ('IN'),
                    )));
            }

    I am missing something. Kindly assist and thank you in advance

Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Query products not in specific categories but include specific products’ is closed to new replies.