Home › Forums › Calendar Products › Events Calendar PRO › Show only particular category in "Related Events"
- This topic has 15 replies, 3 voices, and was last updated 6 years, 3 months ago by Cliff.
-
AuthorPosts
-
January 21, 2018 at 3:53 am #1431730venthi76Participant
Hi,
Came across this post which explains how to exclude categories from “Related Events” – https://theeventscalendar.com/support/forums/topic/exclude-categories-from-related-events/
I need the right opposite – to show ONLY events from a particular category in “Related Events”. Reason being, my category is based on City and logically I prefer more related events for that particular category (city) shown rather than events in some other city (category)
You can visit our url mentioned in private message. Please assist how this can be achieved.
Thanks.
January 21, 2018 at 3:55 am #1431731venthi76ParticipantThis reply is private.
January 22, 2018 at 5:23 pm #1433062CliffMemberHi. That code snippet you linked to looks fine… just change ‘operator’ from ‘NOT IN’ to ‘IN’
Of course, also update your array() for your categories.
Please let me know how this goes for you.
January 22, 2018 at 5:40 pm #1433074venthi76ParticipantNoted but just one query. The category going to be different at events from different category. How to capture this in the code as I cant fix it to one term. Please assist.
`if ( class_exists( ‘Tribe__Events__Main’ ) ) {
add_filter( 'tribe_related_posts_args', 'example_exclude_category_from_related_posts' ); function example_exclude_category_from_related_posts( $args ) { if ( ! is_array( $args ) ) { return $args; } $args['tax_query'][] = array( 'taxonomy' => Tribe__Events__Main::TAXONOMY, 'field' => 'slug', 'terms' => array( 'barbecue' ), 'operator' => 'IN', ); return $args; }
}`
‘terms’ => array( ‘barbecue’ ), – how do i change this to capture the array the particular event belongs to.
- This reply was modified 6 years, 3 months ago by venthi76.
January 22, 2018 at 7:28 pm #1433149CliffMemberSorry I missed that part… that’s actually how it already works by default. It takes into account both Tags and Event Categories.
Is this not how it’s working on your own site with your custom coding removed while using the Twenty Seventeen theme?
January 22, 2018 at 9:56 pm #1433201venthi76ParticipantHi,
What i meant was, if i preset say ‘terms’ => array( ‘london’ ) then in the events category Manchester the related events are not going to be shown since the function calls for london related events to be shown.
How make it dynamic so that on it shows whats relative according to category of event being viewed.
For example
Category London
The related events being shown are from category LondonCategory Manchester
The related events being shown are from category ManchesterJanuary 22, 2018 at 10:01 pm #1433203venthi76ParticipantThis reply is private.
- This reply was modified 6 years, 3 months ago by venthi76.
January 23, 2018 at 5:26 pm #1434186CliffMemberBecause your single event template isn’t the default, you might be using a theme that has some Template Overrides or some custom code that’s already affecting this.
Please switch to the Twenty Seventeen theme and see if you get the same list of Related Events as you are now. If you are, please send a screenshot of your wp-admin list of Event Categories so I can see the parent/child relationships.
January 23, 2018 at 8:11 pm #1434279venthi76ParticipantHi,
I’ve switched to the Twenty Seventeen theme, clear cache but I get the same list of Related Events as I am now.
Screenshot of the Event Category can be viewed at https://www.dropbox.com/s/i5nb83o3pz2x7tt/Event-Categories.jpg?dl=0
Thanks.
- This reply was modified 6 years, 3 months ago by venthi76.
January 23, 2018 at 9:11 pm #1434308CliffMemberHere’s a screenshot of how it appears on my testing site: https://cl.ly/2Z1N3V3o3C3R (no audio)
Could you please send me a link to your site when in Testing for Conflicts Mode (basically switch to Twenty Seventeen theme and deactivate all plugins and custom code other than Modern Tribe plugins)?
Of course, we always recommend restorable database and file backups and doing requested changes on a staging site before modifying anything on your site.
January 23, 2018 at 10:21 pm #1434330venthi76ParticipantHi,
I just rechecked. Apparently, it works like what shown in your video. Except all category in my Event Category, only one category tend to get Related Events mixed up with other Categories. Why such different behavior when the default code still the same.
Please checkout links in private reply.
January 23, 2018 at 10:24 pm #1434331venthi76ParticipantThis reply is private.
January 24, 2018 at 12:52 pm #1435068CliffMemberYour screenshot of the Event Categories didn’t show London so I was curious if maybe it was a parent or child category and therefore in the mix.
However, I think the issue is that your events also have Post Tags. Try this snippet to use only Event Categories in the related events logic:
https://gist.github.com/cliffordp/6a66affeab8ac57d7ceea942f8c417ff
Please let me know how this goes for you.
January 24, 2018 at 9:07 pm #1435427venthi76ParticipantHi Cliff,
The function you provided indeed manage to resolve the issue. The following is just for your review.
Please checkout screenshot of the Event Categories that show London is child category:
https://www.dropbox.com/s/d5fccsi83e85a33/Event-Categories-1.jpg?dl=0Another screenshot just to show we dont have tag named “London”:
https://www.dropbox.com/s/0xw2al2b6nogk13/Event-Tags.jpg?dl=0Please advice.
January 25, 2018 at 2:41 pm #1436505CliffMemberGlad to hear and thanks for the additional information.
-
AuthorPosts
- The topic ‘Show only particular category in "Related Events"’ is closed to new replies.