Order by slug name instead of alphabetical?

Home Forums Calendar Products Filter Bar Order by slug name instead of alphabetical?

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #209786

    We are using category names to sort options in the filter bar. Is there a way to order the items in the filter list by slug rather than alphabetical by the name?

    #210268
    Barry
    Member

    I don’t see why not – can you try adding a short snippet like this to your theme’s functions.php file?

    add_filter( 'tribe_events_filter_values', 'reorder_category_filter_list', 10, 2 );
    
    function reorder_category_filter_list( $list, $slug ) {
    	if ( 'eventcategory' !== $slug ) return $list;
    	usort( $list, 'custom_cat_filter_sort' );
    	return $list;
    }
    
    function custom_cat_filter_sort( $p, $q ) {
    	$slug_p = $p['data']['slug'];
    	$slug_q = $q['data']['slug'];
    
    	if ( $slug_p > $slug_q ) return 1;
    	if ( $slug_q > $slug_p ) return -1;
    	return 0;
    }

    Does that help?

    #210330

    Worked like a charm! Thanks so much!!

    #215293
    Barry
    Member

    My pleasure 🙂

    I’ll go ahead and close this thread – but if we can help with anything else please do feel free to post new threads as needed. Also, if you had a moment to spare, we’d love to hear your thoughts on The Events Calendar so far. Thanks!

Viewing 4 posts - 1 through 4 (of 4 total)
  • The topic ‘Order by slug name instead of alphabetical?’ is closed to new replies.