evavienna
evavienna

Reputation: 1119

Exclude current product and featured products from WP_Query

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 )          
        ));

Upvotes: 0

Views: 353

Answers (1)

urban_biscuit
urban_biscuit

Reputation: 86

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())

Upvotes: 2

Related Questions