Home > OS >  Exclude current product and featured products from WP_Query
Exclude current product and featured products from WP_Query

Time:01-07

Im using the following code (without the post__not_in parts) to query best rated products with wordpress woocommerce in single product view. I need to exclude the current post and feautred posts from the query. Any idea how to exclude both of them at the same time?

        $the_query = new WP_Query( array(           
            // Order by best rated products
            'post_type'      => 'product',
            'post_status'  =>  'publish',
            'posts_per_page' => '-1',           
            'orderby'        => 'meta_value_num',
            'order'          => 'desc',
            'meta_key'       => '_wc_average_rating',
            'post__not_in'   => wc_get_featured_product_ids(),
            'post__not_in'   => array( $post->ID )          
        ));

CodePudding user response:

Have you tried to merge the arrays? Not sure if you can use the post__not_in twice within the same query.

"post__not_in" => array_merge(array( $post->ID ), wc_get_featured_product_ids())
  •  Tags:  
  • Related