Filter bar preselection

Home Forums Calendar Products Filter Bar Filter bar preselection

Viewing 9 posts - 1 through 9 (of 9 total)
  • Author
    Posts
  • #1012161
    Jacob
    Participant

    Helloo modern tribe team,

    I want the filter bar to
    1. preselect 1 certain venue
    2. and display this venue on top of the list

    Can you help me now to configure this?

    Best,
    Jacob

    #1012322
    Nico
    Member

    Hi Jacob,

    Thanks for reaching out to us! I’ll try to help you out on this…

    Unfortunately there’s no configuration available to do this. Per default Venues are ordered by title in the filter, but you can add a filter to change the order of the filter values:


    add_filter( 'tribe_events_filter_values', 'modify_filter_values', 20, 2);
    function modify_filter_values ( $values, $slug ) {
    if($slug == 'venues') {
    // as an example revert the order
    $values = array_reverse ( $values );
    }
    return $values;
    }

    Regarding the selection of the filter you can link users to the filtered URL. For example: http://site.com/events/?tribe_venues%5B%5D=28 (where 28 is desired venue ID). If you want to maintain the URL without changes then maybe a JS snippet to ‘check’ the filter after the page loads is the way to go.

    Please let me know if I understood this correctly in first place,
    Best,
    Nico

    #1012790
    Jacob
    Participant

    Hello Nico,

    Thank you for taking time for me.

    I am wondering if i can order the venue list so that one specific venue is listed on top. Is there a way for that?

    The preselected page is a good solution for me. Please help me how to find out the venue id. I cannot see it when I check the venue list in the WP backend.

    Best,
    Jacob

    #1012828
    Nico
    Member

    Hey Jacob,

    Thanks for following up!

    I am wondering if i can order the venue list so that one specific venue is listed on top. Is there a way for that?

    I guess it’s possible via some php array functions!

    The preselected page is a good solution for me. Please help me how to find out the venue id. I cannot see it when I check the venue list in the WP backend.

    To get the ID of the desired venue, edit it in the backend and the ID will show in the URL just like this: https://cloudup.com/cHlH_HtSXg7

    Please let me know if there’s anything else I can do for you,
    Best,
    Nico

    #1012858
    Jacob
    Participant

    Hello Nico,

    Thank you. I checked out the list, but I can’t find the proper array that could do the job. Do you have a hint for me?

    Thanks for the advise for finding the ID. That idea really serves my wish for the preselected view!

    Best,
    Jacob

    #1012990
    Jacob
    Participant

    Hello Nico,

    I have found the array. In your function proposal I need to replace the array by array_unshift which moves an item to the top of the list. Can you just tell me what to type after the array_unshift? For that I need to find the array name and the value of the array key (my specific venue) in the events calendar code.

    Best wishes,
    Jacob

    #1013182
    Nico
    Member

    Hey Jacob,

    Thanks for trying that out before hitting the forums again, this one requires a bit of PHP knowledge I guess!

    Here’s the snippet, just replace the value for $venue_id with the correct value:

    /* Modify Venues list for FilterBar */
    add_filter( 'tribe_events_filter_values', 'modify_filter_venues', 20, 2);
    function modify_filter_venues ( $filter_values, $slug ) {

    if($slug == 'venues') {
    $venue_id = 99;

    if ( $key = array_search($venue_id, array_column($filter_values, 'value')) ) {
    $selected_venue = array_splice($filter_values, $key, 1);
    array_unshift($filter_values, $selected_venue[0]);
    }
    }

    return $filter_values;
    }

    Please let me know if you can make this work on your site,
    Best,
    Nico

    #1013231
    Jacob
    Participant

    Great, thank you Nico, it works perfectly!!!

    Yipiiieehhh!!!!

    #1013323
    Nico
    Member

    Hey Jacob!

    Stocked to hear this is working for you 🙂

    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.

    Have a great weekend,
    Nico

Viewing 9 posts - 1 through 9 (of 9 total)
  • The topic ‘Filter bar preselection’ is closed to new replies.