Exclude One Category from Upcoming Events List

Home Forums Calendar Products Events Calendar PRO Exclude One Category from Upcoming Events List

Viewing 10 posts - 1 through 10 (of 10 total)
  • Author
    Posts
  • #46047
    Christina
    Participant

    This seems like it should be pretty straight forward, but after looking through previous requests for the same thing there isn’t a solutionI that worked- perhaps because I don’t know where to put the code.

    I need to exclude one event category from showing up on the Upcoming Events List view.

    The question is 1. what is the code that can be used to achieve this, and 2. in which file and where does it go?

    Thanks

    #46118
    Jonah
    Participant

    Hi Christina,

    You can put this code in your themes functions.php file:

    add_action( 'pre_get_posts', 'exclude_events_category' );
    function exclude_events_category( $query ) {

    if ( $query->query_vars['eventDisplay'] == 'upcoming' || $query->query_vars['eventDisplay'] == 'past' && $query->query_vars['post_type'] == TribeEvents::POSTTYPE && !is_tax(TribeEvents::TAXONOMY) && empty( $query->query_vars['suppress_filters'] ) ) {
    $query->set( 'tax_query', array(
    array(
    'taxonomy' => TribeEvents::TAXONOMY,
    'field' => 'slug',
    'terms' => array('2012'),
    'operator' => 'NOT IN'
    )
    )
    );
    }

    return $query;

    … just change the ‘2012’ in terms to whatever the slug of the category you want to exclude is.

    That should do it!

    #46187
    Christina
    Participant

    Thanks. This code causes two problems, however.

    This makes ALL of the posts from that category disappear – not just on the upcoming events list page, but even in it’s own category page. The category displays as empty with the above code in place. I need them to be excluded from the main upcoming events list, but be visible on their own specific category page.

    This also caused the title of the upcoming events list page to have the title of the first event listed. I had fixed that with a little code snipped that manually set the titles, but this code rendered that invalid.

    #46261
    Jonah
    Participant

    Hi Christina,

    Strange, it’s not working right for me either. I wonder if something with our plugin or WordPress changed that affected this. At any rate, I’ve updated the code and this should work:

    add_action( 'pre_get_posts', 'exclude_events_category' );
    function exclude_events_category( $query ) {
    if ( tribe_is_event() && !tribe_is_day() && !is_single() && !is_tax() && !tribe_is_month() ) {
    $query->set( 'tax_query', array(
    array(
    'taxonomy' => TribeEvents::TAXONOMY,
    'field' => 'slug',
    'terms' => array('2012'),
    'operator' => 'NOT IN'
    )
    )
    );
    }
    return $query;
    }

    Does that work for you?

    #46807
    Christina
    Participant

    Nope- I’m getting the same problems : [

    add_action( ‘pre_get_posts’, ‘exclude_events_category’ );
    function exclude_events_category( $query ) {
    if ( $query->query_vars[‘eventDisplay’] == ‘upcoming’ || $query->query_vars[‘eventDisplay’] == ‘past’ && $query->query_vars[‘post_type’] == TribeEvents::POSTTYPE && !is_tax(TribeEvents::TAXONOMY) && empty( $query->query_vars[‘suppress_filters’] ) ) {
    $query->set( ‘tax_query’, array(
    array(
    ‘taxonomy’ => TribeEvents::TAXONOMY,
    ‘field’ => ‘slug’,
    ‘terms’ => array(‘outside-events’),
    ‘operator’ => ‘NOT IN’
    )
    )
    );
    }
    return $query;
    }

    #46829
    Jonah
    Participant

    Hi Christina,

    The code you shared does not include the conditional statements I modified. Can you please try the latest revision and let me know if that works for you.

    Thanks,
    Jonah

    #46894
    Christina
    Participant

    I’m sorry, I copied and pasted the wrong code snippet, but neither work.

    The one you just posted (put below) doesn’t take the events out of the list at all.

    add_action( ‘pre_get_posts’, ‘exclude_events_category’ );
    function exclude_events_category( $query ) {
    if ( tribe_is_event() && !tribe_is_day() && !is_single() && !is_tax() && !tribe_is_month() ) {
    $query->set( ‘tax_query’, array(
    array(
    ‘taxonomy’ => TribeEvents::TAXONOMY,
    ‘field’ => ‘slug’,
    ‘terms’ => array(‘outside-events’),
    ‘operator’ => ‘NOT IN’
    )
    )
    );
    }
    return $query;
    }

    #46940
    Jonah
    Participant

    Hi Christina,

    Very sorry, that last code I shared didn’t seem to work either. I did a bit more checking and this seems to do the trick. Try this: http://snippi.com/s/rd9pqcd

    Let me know whether or not that works!

    – Jonah

    #47371
    UNC Web Services
    Participant

    Hey Jonah, I was trying to do the same thing, but I am getting these php errors from the snippet you posted.

    NOTICE: wp-content/themes/events/functions.php:137 – Undefined index: post_type
    NOTICE: wp-content/themes/events/functions.php:137 – Undefined index: eventDisplay

    In 137 is ln 3 in your query.

    #47374
    Jonah
    Participant

    Hi Jeff,

    Looks like it could be a syntax issue with the code. Please double check that all the single quotes are correct single quotes for code and that you’ve pasted this in your functions.php file correctly (i.e. proper PHP opening/closing tags).

Viewing 10 posts - 1 through 10 (of 10 total)
  • The topic ‘Exclude One Category from Upcoming Events List’ is closed to new replies.