Home › Forums › Calendar Products › Events Calendar PRO › Widget taxonomy filter conflict
- This topic has 4 replies, 2 voices, and was last updated 8 years, 9 months ago by
Ryan.
-
AuthorPosts
-
July 19, 2017 at 11:40 am #1323491
Ryan
ParticipantWhen using the following code snippet to exclude an event category (“Musical Feasts”) from the /events/ page, the “Events List” widget no longer respects the taxonomy filter. Please note that this code snippet was provided by Modern Tribe staff via the support forums.
/* * The Events Calendar Remove Events from Month and List Views * add coding to theme's functions.php * @version 3.12 * modify here with event category slugs: array( 'concert', 'convention' ) */ add_action( 'pre_get_posts', 'tribe_exclude_events_category_month_list' ); function tribe_exclude_events_category_month_list( $query ) { if ( isset( $query->query_vars['eventDisplay'] ) && ! is_singular( 'tribe_events' ) ) { if ( $query->query_vars['eventDisplay'] == 'list' && ! is_tax( Tribe__Events__Main::TAXONOMY ) || $query->query_vars['eventDisplay'] == 'month' && $query->query_vars['post_type'] == Tribe__Events__Main::POSTTYPE && ! is_tax( Tribe__Events__Main::TAXONOMY ) && empty( $query->query_vars['suppress_filters'] ) ) { $query->set( 'tax_query', array( array( 'taxonomy' => Tribe__Events__Main::TAXONOMY, 'field' => 'slug', 'terms' => array( 'musical-feasts' ), 'operator' => 'NOT IN' ) ) ); } } return $query; }When this code snippet is active, the Events List widget will list events from ALL categories despite the fact that I’ve added a taxonomy filter that should only list events from a specific event category (“Concerts”). However, if I click the VIEW MORE button at the bottom of the list, that link does connect to the proper event category archive for the Concerts.
If I comment out the custom code above, the widget works perfectly, so there’s definitely a conflict, but I’m not sure how to resolve this conflict. I need the widget to function properly, but I also need the functionality provided by the code snippet. Any ideas on how to resolve this conflict?
Thank you.
July 20, 2017 at 7:42 pm #1324168Victor
MemberHello Mary!
Thanks for reaching out to us! Let me help you with that.
Try using the following snippet of code instead.
/* * The Events Calendar Remove Events from Month and List Views * add coding to theme's functions.php * @version 3.12 * modify here with event category slugs: array( 'concert', 'convention' ) */ add_action( 'pre_get_posts', 'tribe_exclude_events_category_month_list' ); function tribe_exclude_events_category_month_list( $query ) { if ( isset( $query->query_vars['eventDisplay'] ) && ! is_singular( 'tribe_events' ) ) { if ( $query->query_vars['eventDisplay'] == 'list' && ! is_tax( Tribe__Events__Main::TAXONOMY ) || $query->query_vars['eventDisplay'] == 'month' && $query->query_vars['post_type'] == Tribe__Events__Main::POSTTYPE && ! is_tax( Tribe__Events__Main::TAXONOMY ) && empty( $query->query_vars['suppress_filters'] ) ) { if ( isset( $query->query_vars['tribe_render_context'] ) && $query->query_vars['tribe_render_context'] == 'widget' ) { return; } $query->set( 'tax_query', array( array( 'taxonomy' => Tribe__Events__Main::TAXONOMY, 'field' => 'slug', 'terms' => array( 'musical-feasts' ), 'operator' => 'NOT IN' ) ) ); } } return $query; }Will this work for you? Let me know.
Best,
VictorJuly 20, 2017 at 7:56 pm #1324170Ryan
ParticipantThis code snippet worked perfectly! Thank you for the help.
July 21, 2017 at 6:14 am #1324290Victor
MemberHey Mary!
Glad it worked out for you! 🙂
I’ll close this now, but feel free to open another thread in case anything comes up.
Cheers!
Victor -
AuthorPosts
- The topic ‘Widget taxonomy filter conflict’ is closed to new replies.
