I have wp_query request for give all products, and needs to sort this for 2 fields:
by category & by menu_order.
Various! I need to sort by “menu_order” in each category.
In simple query:
$args = array(
'orderby' =. 'product_cat menu_order'
'posts_per_page' => -1,
'post_type' => 'product',
);
$loop = new WP_Query($args);
In global $product, exist field “menu_order”, but not exist field “product_cat”.
Can I do it with wp_query? Or maybe exist another way to do it?
I was founded right way to do it, code bellow, this example for
More simple way, without pagination and exclude sub categories:
Magic line for this is:
While trying out and search i found a solution to it to use two queries to achieve this purpose the below example might help you achieve your purpose.
<?php
$catargs = array(
);
$categories = get_categories( $catargs );
foreach ($categories as $category) {?>
<h3><?php echo $category->name;
// Category title ?></h3>
<?php
// The Loop
}
?>
Let me know if the method worked for you.