In the woocommerce categories screen you can drag and drop the categories to change their order.
In the “front end” I want to list the categories in this same order (same custom order as per the drag and drop of Product Categories screen in wp-admin).
$args = array(
'taxonomy' => 'product_cat',
'orderby' => 'term_order',
'order' => 'asc',
'show_count' => 0,
'pad_counts' => 0,
'hierarchical' => 1,
'title_li' => '',
'hide_empty' => 0,
);
$query = new WP_Query( $args );
I have tried several different orderby variations but can’t get the exact same order as per the admin screens. The ordering data seems to be stored in the ??__woocommerce_termmeta table with ‘meta_key’ of ‘order’.
Any suggestions would be greatly appreciated.
Thanks.
It seems that WooCommerce is already changing the query in the case of
product_cat
taxonomy. For example:Executed query will look like this:
And categories are taken in the same order as in the admin section.