Hello @milenmk
Thank you for choosing Filter Everything.
If no one from the sorting options was good for you you can use hook ‘wpc_terms_before_display’ to sort them via code. Here is example of how to use the hook – https://filtereverything.pro/resources/hooks/#terms-before-display-hook
Of course this expects that you are familiar with PHP or you have to ask a developer to help you with this.
Hello.
I’ve tried the proposed solutions, but it has no effect.
We have an ACF field, and one that we have a problem with is named Length and has a slug length. The output array for this field is like this:
array(16){
[3]=> object(stdClass)#41944 (6) {
["term_id"]=> int(3)
["slug"]=> string(7) "1000-mm"
["name"]=> string(7) "1000 mm"
["count"]=> int(192) ["cross_count"]=>int(47)
["wp_queried"]=> bool(false)
}
[455]=> object(stdClass)#41945 (6) {
["term_id"]=> int(455)
["slug"]=> string(7) "1100-mm"
["name"]=> string(7) "1100 mm"
["count"]=> int(52)
["cross_count"]=> int(13)
["wp_queried"]=> bool(false)
}
[8]=> object(stdClass)#41982 (6) {
["term_id"]=> int(8)
["slug"]=> string(7) "2000-mm"
["name"]=> string(7) "2000 mm"
["count"]=> int(180)
["cross_count"]=> int(43)
["wp_queried"]=> bool(false)
}
[264]=> object(stdClass)#41874 (6) {
["term_id"]=> int(264)
["slug"]=> string(7) "3000-mm"
["name"]=> string(7) "3000 mm"
["count"]=> int(112)
["cross_count"]=> int(23)
["wp_queried"]=> bool(false)
}
[9]=> object(stdClass)#41873 (6) {
["term_id"]=> int(9)
["slug"]=> string(6) "400-mm"
["name"]=> string(6) "400 mm"
["count"]=> int(152)
["cross_count"]=> int(37)
["wp_queried"]=> bool(false)
}
}
And we’ve tried the proposed solution like this:
function wpc_sort_terms_as_needed( $terms, $filter ) {
// pa_color - is desired taxonomy
if ( $filter['e_name'] == 'length' ) {
$newTerms = [];
foreach ( $terms as $k => $term ) {
$termOrder = get_term_meta( $term->term_id, 'slug', true );
$term->menu_order = ( $termOrder !== false ) ? $termOrder : 0;
$newTerms[ $k ] = $term;
}
// To sort in descending order
// usort( $newTerms, \FilterEverything\Filter\EntityManager::compareDesc('menu_order') );
// To sort in ascending order
usort( $newTerms, EntityManager::compareAsc( 'menu_order' ) );
return $newTerms;
}
return $terms;
}
However, no matter what we try for $termOrder key (slug or name) the result visible on the frontend is:
1000 mm
1200 mm
1400 mm
1600 mm
1800 mm
2000 mm
400 mm
500 mm
600 mm
700 mm
800 mm
900 mm
2300 mm
2600 mm
3000 mm
1100 mm