Sorting tags alphabetically in the filter bar

Home Forums Calendar Products Filter Bar Sorting tags alphabetically in the filter bar

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #1059958
    dschwinler
    Participant

    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 site

    #1060160
    Nico
    Member

    Hey 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,
    Nico

    #1062669
    Maria Alejandra
    Participant

    Hi 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?
    Thanks

    #1062745
    Nico
    Member

    Hola 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,
    Nico

    #1063408
    dschwinler
    Participant

    Thank you Nico!!

    #1063411
    Nico
    Member

    Glad 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

Viewing 6 posts - 1 through 6 (of 6 total)
  • The topic ‘Sorting tags alphabetically in the filter bar’ is closed to new replies.