In woocommerce I need to display products that are members of 2 categories. I am using the following code:
<?php
$args = array( 'post_type' => 'product', 'posts_per_page' => 200, 'product_cat' => 'Washington', 'orderby' => 'rand' );
$loop = new WP_Query( $args );
while ( $loop->have_posts() ) : $loop->the_post(); global $product; ?>
I would like to display products which are members of both the categories “Washington” and “Small Single”
I do not want to display all products from “Washington”, then all products from “Small Single”, I would like to display all products which are members of both categories
How would I amend the above code to include the category “Small Single”?
It is possible with
category__and
parameter.1) USE
Category IDs
of"Washington" and "Small Single"
2) In your
$args
Adjust below parameter.(I assumeWashington catId = 2
andSmall Single CatID = 6
)3) It will only display Products contained in Both category.
I hope, It will help you!
Had the same requirement, turned out to be very simple