Home › Forums › Calendar Products › Events Calendar PRO › Add meta query to default calendar view
- This topic has 4 replies, 3 voices, and was last updated 7 years, 6 months ago by sparxoo.
-
AuthorPosts
-
October 25, 2016 at 11:28 am #1182719sparxooParticipant
Hi,
I’m trying to add a meta query to the default calendar template. Basically I’m creating a website where each user is a part of a club and each club has their own events. So for instance the user is in club 100, I need to only grab events that belong to club 100. I have added a custom field to the events in order to add the club number, i’m just wondering if there’s a way to query the posts on the default view without having to use tribe_get_events and creating my own template.
October 26, 2016 at 1:08 pm #1183378NicoMemberHi there @sparxoo,
Thanks for getting in touch with us! I can help you on this ๐
I’m not 100% sure that I understand correctly what you are trying to do here, but I guess it’s just modifying the calendar main query. Take a look at the code sample below:
/* Tribe, limit posts just to a category */
add_action( 'pre_get_posts', 'limit_events_category' );
function limit_events_category( $query ) {
if ( $query->query_vars['post_type'] == TribeEvents::POSTTYPE && !is_tax(TribeEvents::TAXONOMY) && empty( $query->query_vars['suppress_filters'] ) ) {$query->set( 'tax_query', array(
array(
'taxonomy' => TribeEvents::TAXONOMY,
'field' => 'slug',
'terms' => array('results'),
'operator' => 'IN'
)));
}
}
It’s just a starting point but I guess it will give you the base to craft your customization!
Please let me know about it,
Best,
NicoOctober 27, 2016 at 9:58 am #1183907sparxooParticipantAwesome, this is exactly what I was looking for. I just swapped out tax_query for a meta_query and it worked great. Thanks!
October 27, 2016 at 2:24 pm #1184058 -
AuthorPosts
- The topic ‘Add meta query to default calendar view’ is closed to new replies.