Reputation: 554
I show a list of categories on the main page. I need the last category to be second. I studied the sorting options, but they are not suitable.
By name, by ID, randomly. Сategory with id "50" need to be second on the list.
add_filter( 'storefront_product_categories_args', 'custom_storefront_product_categories');
function custom_storefront_product_categories( $args ) {
$args['limit'] = 9;
$args['columns'] = 3;
$args['orderby'] = 'id'; // sort by id category
return $args;
}
EDIT:
I have tried to add the product categories sorted IDs using:
function custom_storefront_category_filtering( $args ) {
$args['ids'] = '16,50,17,18,19,20,21,22,23'; // need such a sequence of categories
return $args;
}
add_filter('storefront_product_categories_shortcode_args','custom_storefront_category_filtering' );
But it only include the product categories.
Upvotes: 1
Views: 1320
Reputation: 253921
As product categories are a custom taxonomy id
, ids
or even ID
will not work. Instead you will use term_id
which is the appropriated argument value for orderby
argument in this context.
Why? because we don't target post IDs but terms IDs.
So in your filter hook:
add_filter( 'storefront_product_categories_args', 'custom_storefront_product_categories');
function custom_storefront_product_categories( $args ) {
$args['limit'] = 9;
$args['columns'] = 3;
$args['orderby'] = 'term_id';
return $args;
}
Code goes in function.php file of your active child theme (or active theme). Tested and works.
Upvotes: 1