Exclude Category from Main Calendar, include category in Calendar, See Admin

Home Forums Calendar Products Events Calendar PRO Exclude Category from Main Calendar, include category in Calendar, See Admin

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #1399857
    Charmaine Taylor
    Participant

    I need to do several things all relating to one event category, “yoga.”

    1. exclude “yoga” category from the main calendar
    2. include a category specific calendar with “yoga” only
    3. View all events in the admin back end

    I am using a WordPress plugin that gives you the ability to easily and safely add your custom functions (PHP code) called My Custom Functions.

    The first code I used accomplished #1 and #2, BUT Not #3. All of the events in the “yoga” category were not accessible in the admin back end at all. They were not visible.

    The code below is my second attempt.
    With this code, #1 is accomplished Main Calendar exclude yoga and #3 is accomplished – all events are in the admin area. BUT NOT #2 – the Yoga Only calendar shows no events.

    <?php
    /*
     * Removes categories "yoga" from list and month views
     */
    function tribe_exclude_events_category( $wp_query ) {
    
    	// Slugs for the categories you wish to hide
    	$exclude_cats = array('yoga');
    
    	// Include all posts on admin views
    	if ( is_admin() ) return $wp_query;
    
    	// Uncomment to allow admins to view all events
    //	if ( current_user_can('administrator') ) return $wp_query;
    
    	// Join with current tax query if set
    	if (is_array($wp_query->tax_query))
    		$tax_query = $wp_query->tax_query;
    	else
    		$tax_query = array();
    
    	// Setup an exclude from the tribe_events_cat taxonomy
    	$tax_query[] = array(
    		'taxonomy'  => 'tribe_events_cat',
    		'field'     => 'slug',
    		'terms'     => $exclude_cats,
    		'operator'  => 'NOT IN'
    	);
    
    	if (
    		tribe_is_event_query()
    //		&& !is_single() // Uncomment to allow directly viewing an individual event page
    //		&& !is_tax() // Uncomment to allow directly viewing the category page
    	) {
    		$wp_query->set('tax_query', $tax_query);
    	}
    
    	return $wp_query;
    
    }
    
    add_action( 'pre_get_posts', 'tribe_exclude_events_category', 100, 1 );
    
    /**
     * Limit events by category in Month, Photo, Week and list view
     * unless we are in a category view
     */
    function limit_events_by_category( $query ) {
    
    	if ( ( tribe_is_month() || tribe_is_photo() || tribe_is_week() || tribe_is_list_view() ) && !is_tax() ) {
    
    		$query->set( 'tax_query', array(
    			array(
    			'taxonomy' => TribeEvents::TAXONOMY,
    			'field' => 'slug',
    			'terms' => array('yoga')
    			))
    		);
    
    	}
    
    	return $query;
    }
    
    add_action( 'pre_get_posts', 'limit_events_by_category' );
    
    #1400146
    Charmaine Taylor
    Participant

    Please help!

    #1401275
    Victor
    Keymaster

    HiĀ Charmaine!

    Thanks for getting in touch with us! Let me help you with this topic.

    First, please let me note that we are fairly limited in how much support we can give for custom development questions like that.

    That said, we always like helping out and at least point users into the right direction as much possible.

    I think that you are pretty close to achieve your goal. Please try only using the first function and remove theĀ limit_events_by_category() function. Also, try uncommenting the following line:

    // && !is_tax() // Uncomment to allow directly viewing the category page

    that will make the taxonomy page to show yoga classes.

    I hope that helps! Let me know about it.

    Best,
    Victor

    #1415078
    Support Droid
    Keymaster

    Hey there! This thread has been pretty quiet for the last three weeks, so we’re going to go ahead and close it to avoid confusion with other topics. If you’re still looking for help with this, please do open a new thread, reference this one and we’d be more than happy to continue the conversation over there.

    Thanks so much!
    The Events Calendar Support Team

Viewing 4 posts - 1 through 4 (of 4 total)
  • The topic ‘Exclude Category from Main Calendar, include category in Calendar, See Admin’ is closed to new replies.