Show only particular category in "Related Events"

Home Forums Calendar Products Events Calendar PRO Show only particular category in "Related Events"

Viewing 15 posts - 1 through 15 (of 15 total)
  • Author
    Posts
  • #1431730
    venthi76
    Participant

    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.

    #1431731
    venthi76
    Participant

    This reply is private.

    #1433062
    Cliff
    Member

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

    #1433074
    venthi76
    Participant

    Noted 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.
    #1433149
    Cliff
    Member

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

    #1433201
    venthi76
    Participant

    Hi,

    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 London

    Category Manchester
    The related events being shown are from category Manchester

    #1433203
    venthi76
    Participant

    This reply is private.

    • This reply was modified 6 years, 3 months ago by venthi76.
    #1434186
    Cliff
    Member

    Because 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.

    #1434279
    venthi76
    Participant

    Hi,

    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.
    #1434308
    Cliff
    Member

    Here’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.

    #1434330
    venthi76
    Participant

    Hi,

    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.

    #1434331
    venthi76
    Participant

    This reply is private.

    #1435068
    Cliff
    Member

    Your 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.

    #1435427
    venthi76
    Participant

    Hi 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=0

    Another screenshot just to show we dont have tag named “London”:
    https://www.dropbox.com/s/0xw2al2b6nogk13/Event-Tags.jpg?dl=0

    Please advice.

    #1436505
    Cliff
    Member

    Glad to hear and thanks for the additional information.

Viewing 15 posts - 1 through 15 (of 15 total)
  • The topic ‘Show only particular category in "Related Events"’ is closed to new replies.