I am trying to fetch All product by category. I am unable to fetch product by custom category. I do no what is wrong with this and why this code is not working .Any help Please
<?php $ terms = get_terms(array('taxonomy' => 'item', 'hide_empty' => false, 'parent' => 0, 'orderby' => 'date', 'order' => 'DESC')); foreach ($ terms as $ term) { $ slug = $ term->slug; $ term_id = $ term->term_id; $ args = array( 'post_type' => 'product', 'tax_query' => array( array( 'taxonomy' => 'item', 'terms' => $ slug, 'field' => 'slug', ) ), 'orderby' => 'ID', 'order' => 'DESC', 'posts_per_page' => -1 ); $ loop = new WP_Query( $ args ); //print_r($ loop); ?> <div id="<?php echo $ term_id = $ term->term_id; ?>" class="tabcontent"> <?php while ( $ loop->have_posts() ) : $ loop->the_post(); global $ product; ?> <?php echo '<br /><a href="'.get_permalink().'">' . woocommerce_get_product_thumbnail().' '.get_the_title().'</a>';?> <?php endwhile;?> </div> <?php }//Close foreach here ?> </div> <?php wp_reset_query(); ?>