Home › Forums › Calendar Products › Events Calendar PRO › Hide category from calendar views not working
- This topic has 8 replies, 2 voices, and was last updated 10 years, 5 months ago by
Brian.
-
AuthorPosts
-
November 9, 2015 at 9:49 am #1023308
integrity
ParticipantI wanted to report an issue I came across while perusing the following knowledgebase post: Hide category from calendar views https://theeventscalendar.com/knowledgebase/hide-category-from-calendar-views/
This code snippet does not appear to work on the latest version of the Event Calendar Pro plugin (v 3.12.6).
Here is the modified code I have put into my functions.php file. The ‘convention-center’, ‘member-events’, ‘edward-jones-dome’ event categories already exist on my site and have serval posts within them but are still showing up on the main “/events/” page.
/*
* Removes categories “convention-center”, “edward-jones-dome” and “member-events” from list and month views
*/
function tribe_exclude_events_category( $wp_query ) {// Slugs for the categories you wish to hide
$exclude_cats = array(‘convention-center’, ‘member-events’, ‘edward-jones-dome’);// 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 );
Can you please help me figure out how to get this working?
November 9, 2015 at 5:20 pm #1023526Brian
MemberHi,
That snippet does not appear to be working.
Try this one instead:
https://gist.github.com/jesseeproductions/a467b28a8b8010d4015b
Change this:
array('tech')With this
array( 'convention-center', 'member-events', 'edward-jones-dome' )If that is still not working, please check your slugs for the event categories as I have tested this snippet today and it works for me.
Let me know how that works out.
Thanks
November 10, 2015 at 7:36 am #1023734integrity
ParticipantHi Brian,
Thanks for the help. Your code snippet does work BUT appears to create some PHP warnings and notices…
Notice: Undefined index: eventDisplay in /Users/arod/Library/Developer/Web/explorestl/app/wp-content/themes/explore-st-louis/inc/override.php on line 84 Warning: Cannot modify header information - headers already sent by (output started at /Users/arod/Library/Developer/Web/explorestl/app/wp-content/themes/explore-st-louis/inc/override.php:84) in /Users/arod/Library/Developer/Web/explorestl/app/wp-admin/post.php on line 242Any recommendation on how I can resolve these warnings and notices?
Thanks
November 10, 2015 at 7:57 am #1023751integrity
ParticipantI was able to remove all of the warnings from showing up in the admin by adding:
if ( is_admin()) return $query;as the first line of the exclude_events_category function…
the
NOTICE: wp-content/themes/explore-st-louis/inc/override.php:86 - Undefined index: eventDisplayis still showing up on the frontend however…
November 10, 2015 at 8:10 am #1023755Brian
MemberHi,
Warnings and notices only show if debug is on. So at least on a live site that should be off.
However, I did update the snippet to prevent those from happening now.
Please check the gist again and try the new coding and let me know how that works out.
Thanks
November 10, 2015 at 8:37 am #1023780integrity
ParticipantThat fixes the notice that was showing up on all event list views, but now the following notice appears on all event detail views…
Notice: Trying to get property of non-object in /Users/arod/Library/Developer/Web/explorestl/app/wp-includes/query.php on line 4519While I understand these are just notices from the PHP compiler and nothing is broken, I’d prefer not to have them.
Thanks for your continued support!
November 10, 2015 at 10:34 am #1023846Brian
MemberI updated the snippet and reordered the part.
I think it is fine now, but if not I am not sure the issue and that is about all I can provide on this for now.
Thanks
November 11, 2015 at 7:24 am #1024196integrity
ParticipantWorks like a charm!
Thanks for all your help!
November 11, 2015 at 7:32 am #1024204Brian
MemberGreat, glad it helps, I am going to go ahead and close this ticket, but if you need help on this or something else please post a new ticket.
Thanks!
-
AuthorPosts
- The topic ‘Hide category from calendar views not working’ is closed to new replies.
