I'm trying to exclude the current product by using the code below, but instead of excluding, it retrieves all the default posts and not products. Probably it's not working at all.
<?php
global $post;
$terms = get_the_terms( $post->ID, 'product_cat' );
foreach ($terms as $term ) {
$product_cat_name = $term->name;
break;
}
$ids = array();
$currentID = get_the_ID();
$args = array('post_type' => 'product', 'product_cat' => $product_cat_name, 'post__not_in' => array($currentID));
$loop = new WP_Query( $args );
while ( $loop->have_posts() ) : $loop->the_post(); global $product;
$ids[] = $loop->post->ID;
endwhile;
wp_reset_query();
print_r($ids);
?>
Using this will include the current post and it displays the product only.
<?php
global $post;
$terms = get_the_terms( $post->ID, 'product_cat' );
foreach ($terms as $term ) {
$product_cat_name = $term->name;
break;
}
$ids = array();
$currentID = get_the_ID();
$args = array('post_type' => 'product', 'product_cat' => $product_cat_name);
$loop = new WP_Query( $args );
while ( $loop->have_posts() ) : $loop->the_post(); global $product;
$ids[] = $loop->post->ID;
endwhile;
wp_reset_query();
print_r($ids);
?>
