Woocommerce products query - order_by
woocommerce, wordpress
Solution
Remove `'menu_order' => 'asc'` part from `tax_query` and add to main, that should work:
$args = array(
'post_type' => 'product',
'stock' => 1,
'posts_per_page' => 99,
'orderby' => 'menu_order',
'order' => 'ACS',
'tax_query' => array(
'relation' => 'OR',
array(
'taxonomy' => 'product_cat',
'field' => 'slug',
'terms' => 'system_components'
),
array(
'taxonomy' => 'product_cat',
'field' => 'slug',
'terms' => 'add-ons'
)
),
'meta_query' => array(
array(
'key' => '_visibility',
'value' => 'hidden',
'compare' => '!='
)
));
As you can see in the documentation, the `tax_query` hasn't parameter `menu_order`.
Problem
I am using a query in my template.php file to display `wooCommerce` products by category. My query looks like this: ``` <?php $args = array( 'post_type' => 'product', 'stock' => 1, 'posts_per_page' => 99, 'tax_query' => array( 'relation' => 'OR', array( 'taxonomy' => 'product_cat', 'field' => 'slug', 'terms' => 'system_components', 'menu_order' => 'asc' ), array( 'taxonomy' => 'product_cat', 'field' => 'slug', 'terms' => 'add-ons', 'menu_order' => 'asc' ) ), 'meta_query' => array( array( 'key' => '_visibility', 'value' => 'hidden', 'compare' => '!=' ) )); $loop = new WP_Query($args); if ($loop->have_posts()) { while ($loop->have_posts()) : $loop->the_post(); ?> ..... ``` This works, and I can see the products I want and the one I don't want are not visible. The only bit I don't understand is that `'menu_order' => 'ASC'` doesn't seem to work. I doesn't' matter what I type as menu order in the product settings, the order doesn't change. What am I doing wrong here? Thanks