Smoking Sheriff
Smoking Sheriff

Reputation: 471

How to orderby woocommerce product categories as in the order I want?

This is the query arguments. I want my products to appear according to categories arranged in the order I want.

$query_args = array(
    'post_type' => 'product',
    'post_status' => 'publish',
    'ignore_sticky_posts' => 1,
    'posts_per_page' => $post_per_page,
    'orderby' => 'name',
    'order' => 'DESC',
    'paged' => $paged,
    'tax_query' => array(
                array('taxonomy' => 'product_cat',
                      'field' => 'term_id',
                      'terms' => 12,
                      'operator' => 'NOT IN',           
                     )
     )
);
$wp_query = new WP_Query($query_args);

Means, I want to specify the category order in the query somewhere..

array(3,4,5,7)

And products from category 3 will appear first, then 4, then 5 and so on. How can I achieve this? Tried this plugin, but it seems it's not working with a custom query. https://wordpress.org/plugins/taxonomy-terms-order/

Upvotes: 2

Views: 3864

Answers (1)

user3398549
user3398549

Reputation: 31

  1. Just go under Appearance->Widgets
  2. List item Under sidebar you added Woocommerce Product Categories expand "Woocommerce Product Categories"
  3. List item At Order By dropdown box choose "Category Order" instead of Name.

Upvotes: 1

Related Questions