Home › Forums › Calendar Products › Filter Bar › Sorting tags alphabetically in the filter bar
- This topic has 5 replies, 3 voices, and was last updated 8 years, 3 months ago by Nico.
-
AuthorPosts
-
January 21, 2016 at 7:40 am #1059958dschwinlerParticipant
Hello,
I’m using tags for cities in the filter bar. I’m wondering if I can have the tags (cities) be listed out alphabetically from top to bottom? To do this would I need a tag taxonomy plugin or could I modify the existing code?
My siteJanuary 21, 2016 at 3:06 pm #1060160NicoMemberHey David,
Thanks for reaching out to us on this – I’ll help you out!
I think that tags already come ordered alphabetically (a-z), because that’s the default order for get_tags (the WordPress function that gets the values for the filter). I’ll leave a code sample of how to modify the results before displayed:
/*
* The Events Calendar - Change filter values order
*/
add_filter( 'tribe_events_filter_values', 'tribe_re_order_filter_tags', 10, 2 );function tribe_re_order_filter_tags ( $values , $slug ){
if ( $slug == 'tags' ) {
sort($values); // a-z
//rsort($values); // z-a
}return $values;
}
Paste this snippet in the theme functions.php file located at wp-content/themes/your_theme/ and that should let you re-order the filters.Please let me know if this is what you were looking for,
Best,
NicoJanuary 26, 2016 at 11:42 am #1062669Maria AlejandraParticipantHi Nico
how can i set the order with an index? maybe thats not posible…
On that case would like to order by id, how can i do that?
ThanksJanuary 26, 2016 at 2:58 pm #1062745NicoMemberHola Maria,
Thanks for jumping in!
how can i set the order with an index? maybe thats not posible…
Sure it’s possible just use the code I’ve sent to David in my previous reply, but instead of using the sort function, use the ksort to order by array key, which in this case is the same as the tag id.
Please give a try and let me know if it works as expected,
Best,
NicoJanuary 27, 2016 at 1:48 pm #1063408dschwinlerParticipantThank you Nico!!
January 27, 2016 at 1:55 pm #1063411NicoMemberGlad to be of service David!
I’ll go ahead and close out this thread, but if you need help with anything else please don’t hesitate to create a new one and we will be happy to assist you.
Best,
Nico -
AuthorPosts
- The topic ‘Sorting tags alphabetically in the filter bar’ is closed to new replies.