Widget taxonomy filter conflict

Home Forums Calendar Products Events Calendar PRO Widget taxonomy filter conflict

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #1323491
    Ryan
    Participant

    When 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.

    #1324168
    Victor
    Member

    Hello 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,
    Victor

    #1324170
    Ryan
    Participant

    This code snippet worked perfectly! Thank you for the help.

    #1324290
    Victor
    Member

    Hey 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

Viewing 4 posts - 1 through 4 (of 4 total)
  • The topic ‘Widget taxonomy filter conflict’ is closed to new replies.