Home › Forums › Calendar Products › Events Calendar PRO › Exclude One Category from Upcoming Events List
- This topic has 9 replies, 3 voices, and was last updated 11 years ago by Jonah.
-
AuthorPosts
-
April 16, 2013 at 8:58 pm #46047ChristinaParticipant
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
April 17, 2013 at 12:56 pm #46118JonahParticipantHi 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!
April 17, 2013 at 9:59 pm #46187ChristinaParticipantThanks. 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.
April 18, 2013 at 3:29 pm #46261JonahParticipantHi 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?April 24, 2013 at 8:12 pm #46807ChristinaParticipantNope- 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;
}April 25, 2013 at 9:33 am #46829JonahParticipantHi 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,
JonahApril 25, 2013 at 7:34 pm #46894ChristinaParticipantI’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;
}April 26, 2013 at 9:49 am #46940JonahParticipantHi 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
May 1, 2013 at 9:47 am #47371UNC Web ServicesParticipantHey 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: eventDisplayIn 137 is ln 3 in your query.
May 1, 2013 at 9:57 am #47374JonahParticipantHi 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).
-
AuthorPosts
- The topic ‘Exclude One Category from Upcoming Events List’ is closed to new replies.