Woocommerce get products using multiple category ID's
I'm trying display products from muliple categories using the category
ID's, I've managed to display the product category name (which was a pain)
and this works fine if I wanted to get products from a single category but
obviously dosn't work if the product is in multiple categories. I need
help getting the product category ID and making this work with getting all
posts within this category no matter if it is in multiple categories or
not. Any help, advice or tips would greatly be appreciated.
<?php
global $post, $product;
$categ = $product->get_categories();
$categ2 = preg_replace('/<a href=\"(.*?)\">(.*?)<\/a>/',"\\2",
$categ);
echo $categ2; /* TEST */
?>
<?php
global $product;
$args = array( 'post_type' => 'product', 'posts_per_page' =>
'999', 'product_cat' => $categ2, );
$loop = new WP_Query( $args );
while ( $loop->have_posts() ) : $loop->the_post(); global $product;
?>
No comments:
Post a Comment