Hide category from calendar views not working

Home Forums Calendar Products Events Calendar PRO Hide category from calendar views not working

Viewing 9 posts - 1 through 9 (of 9 total)
  • Author
    Posts
  • #1023308
    integrity
    Participant

    I 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?

    #1023526
    Brian
    Member

    Hi,

    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

    #1023734
    integrity
    Participant

    Hi 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 242
    

    Any recommendation on how I can resolve these warnings and notices?

    Thanks

    #1023751
    integrity
    Participant

    I 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: eventDisplay

    is still showing up on the frontend however…

    #1023755
    Brian
    Member

    Hi,

    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

    #1023780
    integrity
    Participant

    That 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 4519

    While 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!

    #1023846
    Brian
    Member

    I 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

    #1024196
    integrity
    Participant

    Works like a charm!

    Thanks for all your help!

    #1024204
    Brian
    Member

    Great, 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!

Viewing 9 posts - 1 through 9 (of 9 total)
  • The topic ‘Hide category from calendar views not working’ is closed to new replies.