Home › Forums › Calendar Products › Events Calendar PRO › Calendar Grid View – Filter Events by Venue
- This topic has 7 replies, 3 voices, and was last updated 13 years, 10 months ago by
Jonah.
-
AuthorPosts
-
May 31, 2012 at 4:12 am #19988
Kirsty
MemberIs 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.
May 31, 2012 at 2:53 pm #20014Jonah
ParticipantHi 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
June 11, 2012 at 1:00 pm #20489Jason
MemberThis 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.
June 11, 2012 at 4:38 pm #20498Jonah
ParticipantHey 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
June 11, 2012 at 8:17 pm #20540Jason
MemberThanks 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]June 12, 2012 at 7:04 pm #20598Jonah
ParticipantHmmmm, 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
June 13, 2012 at 12:37 pm #20632Jason
MemberJonah, 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;
}
}June 13, 2012 at 4:32 pm #20641Jonah
ParticipantHey 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' => '='
)
)
-
AuthorPosts
- The topic ‘Calendar Grid View – Filter Events by Venue’ is closed to new replies.
