Home › Forums › Calendar Products › Events Calendar PRO › Exclude Category from Main Calendar, include category in Calendar, See Admin
- This topic has 4 replies, 2 voices, and was last updated 6 years, 4 months ago by Charmaine Taylor.
-
AuthorPosts
-
December 6, 2017 at 2:43 pm #1399857Charmaine TaylorParticipant
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 endI 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' );
December 7, 2017 at 3:51 am #1400146Charmaine TaylorParticipantPlease help!
December 8, 2017 at 8:05 am #1401275VictorKeymasterHiĀ 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,
VictorDecember 30, 2017 at 8:35 am #1415078Support DroidKeymasterHey 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 -
AuthorPosts
- The topic ‘Exclude Category from Main Calendar, include category in Calendar, See Admin’ is closed to new replies.