Home › Forums › Calendar Products › Events Calendar PRO › Exclude Category from BOTH Gridview and Listview
- This topic has 8 replies, 3 voices, and was last updated 8 years, 9 months ago by Support Droid.
-
AuthorPosts
-
June 14, 2012 at 9:57 am #20673DenisMember
Hi. I need some help. Can’t figure it out how to exclude categories both Gridview and Listview. Looked through this forum, but there is no good solution.
1. U can exclude it from Grid (functions.php) – https://gist.github.com/2931459
2. Or u can exclude it from Grid (table.php) – https://gist.github.com/2931458
3. Also u can exclude it from List (list.php) – https://gist.github.com/29314571 and 2 works fine.
3 works, BUT it crashes pages and page selection links in listview (same over here – https://theeventscalendar.com/support/forums/topic/removing-one-category-of-events-from-main-event-list-and-calendar/ )So I kinda need a solution that excludes it from both type of view.
June 17, 2012 at 8:16 am #20738DenisMemberEh, I need some support over here…
June 17, 2012 at 8:49 pm #20758JonahParticipantHey Denis, how about this:
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['eventDisplay'] == 'month' && $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('presentations'),
'operator' => 'IN'
)
)
);
}return $query;
}
June 18, 2012 at 2:05 am #20762DenisMemberYou mean including only those categories that i need? It’s not a solution for me – client won’t be happy to ask me changing php-file every time he adds a new category.
June 18, 2012 at 9:35 am #20778JonahParticipantHey Denis,
No you change the operator used for the tax_query to ‘NOT IN’ and then have it exclude. You can read more up on tax_query here: http://codex.wordpress.org/Class_Reference/WP_Query#Taxonomy_Parameters
I hope that helps!
– Jonah
June 19, 2012 at 3:31 am #20830DenisMemberThank you! It did help!
June 19, 2012 at 3:42 am #20832DenisMemberBut there is 1 more thing…
Now i have a hidden category for second calendar.
This category is hidden from both gridview and listview – http://itrackdays.ru/events/
And u can see it in category’s gridview – – http://itrackdays.ru/events/category/karting-2
But category’s listview is empty – http://itrackdays.ru/events/category/karting-2/predstoyashheeJune 21, 2012 at 8:07 am #20963JonahParticipantHi Denis,
Last little tip I can provide on this, you’ll need to figure out the rest on your own or hire a developer. Try adding these additional conditions to only filter out the category to be excluded if we are not on a category for the upcoming or past lists:
add_action( 'pre_get_posts', 'exclude_events_category' );
function exclude_events_category( $query ) {if ( $query->query_vars['eventDisplay'] == 'upcoming' && !is_tax(TribeEvents::TAXONOMY) || $query->query_vars['eventDisplay'] == 'past' && !is_tax(TribeEvents::TAXONOMY) || $query->query_vars['eventDisplay'] == 'month' && $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;
}
I hope that helps!– Jonah
July 7, 2015 at 6:21 am #977147Support DroidKeymasterThis topic has not been active for quite some time and will now be closed.
If you still need assistance please simply open a new topic (linking to this one if necessary)
and one of the team will be only too happy to help. -
AuthorPosts
- The topic ‘Exclude Category from BOTH Gridview and Listview’ is closed to new replies.