How to display a list of the products of the current category?
-
Hello
My structure of products is as follows:
Notebooks (category)
–Samsung (subcategory)
—- Product1
—- Product2
—- Product3
–Asus (subcategory)
—- Product4
—- Product5
Smartphones (category)
–Samsung (subcategory)
—- Product6
—- Product7How to determine a product category and subcategory, and then display a list of all the products of the current subcategory with product name, price and permalink?
Now, I am printing the entire list of products with the following code.
But I do not understand how to limit its current sub-category.$ordering_args = $woocommerce->query->get_catalog_ordering_args( $orderby, $order );
$args = array
(‘post_type’=> ‘product’,
‘post_status’ => ‘publish’,
‘ignore_sticky_posts’ => 1,
‘orderby’ => $ordering_args[‘orderby’],
‘order’ => $ordering_args[‘order’],
‘meta_query’=> array (
array
(
‘key’=> ‘_visibility’,
‘value’ => array(‘catalog’, ‘visible’),
‘compare’ => ‘IN’
)
),
‘tax_query’ => array(
array
(
‘taxonomy’ => ‘product_cat’,
‘terms’ => array( esc_attr($category) ),
‘field’ => ‘slug’,
‘operator’ => ‘IN’
)
)
);ob_start();
$products = new WP_Query( $args );if ( $products->have_posts() ) : ?>
<?php //woocommerce_product_loop_start(); ?>
<?php //woocommerce_product_loop_end(); ?>
endif;
- The topic ‘How to display a list of the products of the current category?’ is closed to new replies.