Calendar Grid View – Filter Events by Venue

Home Forums Calendar Products Events Calendar PRO Calendar Grid View – Filter Events by Venue

Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #19988
    Kirsty
    Member

    Is there a way for me to only show events in the calendar grid view for a particular Venue?

    I have 3 venues which have different events and would like website users to see only the events at the Venue they select, perhaps from a dropdown.

    #20014
    Jonah
    Participant

    Hi Kirsty, this is certainly possible but too complex for us to be able to offer a solution at this time. Ultimately you’re going to want to do something with the pre_get_posts function in WordPress to modify the query. Here is an example but you’ll need to figure out a way to pass in the venue ID based upon a drop down selected:

    add_action( 'pre_get_posts', 'filter_by_venue' );
    function filter_by_venue( $query ) {

    if ( $query->query_vars['post_type'] == TribeEvents::POSTTYPE && $query->query_vars['eventDisplay'] == 'month' && !is_tax(TribeEvents::TAXONOMY) && empty( $query->query_vars['suppress_filters'] ) ) {
    $query->set('venue',$venue_id);
    }

    return $query;

    }

    I hope that helps!

    – Jonah

    #20489
    Jason
    Member

    This does not work. I added this code to my page template, prior to calling tribe_calendar_grid(), and it still displays all events, regardless of what venue ID I use. I know the venue ID is correct, and I made sure the filter_by_venue() function was running. So, I’m at a loss at to how to accomplish this.

    #20498
    Jonah
    Participant

    Hey Jason,

    Oh, well the above code is only going to execute if the if condition is true and that condition checks whether you are viewing the main calendar page, not a page where you have the calendar embedded. So, you’ll need to account for that in the code so it executes for whatever page you’ve got the embed in.

    – Jonah

    #20540
    Jason
    Member

    Thanks for the reply Jonah!
    I thought that may have been the issue, but I completely removed the IF statement, and the same thing is still occurring. For some reason, the “venue” argument is not getting passed properly. I did some debugging in tribe-event-query.class.php, and the setupQueryArgs method is not detecting the “venue” argument at all.

    I even went so far as to manually set the _EventVenueID in the meta_query with the same result. It’s just not going through.

    [code]
    add_action( ‘pre_get_posts’, ‘filter_by_venue’ );
    function filter_by_venue( $query ) {
    $query->set(‘venue’, 12);
    return $query;
    }
    get_header();
    [/code]

    #20598
    Jonah
    Participant

    Hmmmm, are you putting this code in your functions.php file? It won’t work in anything else. I see the get_header() call so that’s why I’m asking…

    – Jonah

    #20632
    Jason
    Member

    Jonah, you’re right! I wasn’t putting the filter into functions.php. So, I added the code to functions.php, but using $query->set(‘venue’, $venueId) didn’t seem to work for me. I var_dump’d the $query from within the filter, and while the “venue” query_var was being added, and the new $query returned, the TribeEventsQuery class wasn’t seeing the query_var in its setupQuery() method when I var_dump’d the $query there. Very strange.

    So, my solution was the following:

    add_action( ‘pre_get_posts’, ‘filter_events_by_venue’ );
    function filter_events_by_venue( $query ) {
    if ($query->query_vars[‘post_type’] === ‘tribe_events’) {
    $venue = get_query_var(‘tribe_venue’);
    $query->query_vars[‘meta_query’][] = array(‘key’=>’_EventVenueID’, ‘value’=>get_venue_id($venue));
    return $query;
    }
    }

    #20641
    Jonah
    Participant

    Hey Jason,

    Sorry, I believe because the ‘venue’ query_var is not a standard one in WordPress and more plugin specific, it does not work with this filter. Your solution is the way to make it working or you could also use meta_query like so:

    $query->set('meta_query', array(
    array(
    'key' => '_EventVenueID',
    'value' => 421,
    'compare' => '='
    )
    )

Viewing 8 posts - 1 through 8 (of 8 total)
  • The topic ‘Calendar Grid View – Filter Events by Venue’ is closed to new replies.