Can the Related Events be associated with a particular category?

Home Forums Calendar Products Events Calendar PRO Can the Related Events be associated with a particular category?

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #1142059
    brucewgresham
    Participant

    Can related events be show events that are in the same category

    We have 5 categories and the related events appear to me to be random.

    Bruce

    #1142083
    George
    Participant

    Hey Bruce,

    Events Calendar Pro’s “related events” are retrieved by way of a function called tribe_get_related_posts(), which you can find in your Events Calendar Pro plugin files at this location:

    events-calendar-pro/src/functions/template-tags/general.php

    That function uses the event categories of the event—and any tags as well—to find “related” / similar events.

    1. Do your events have multiple event categories, typically? This may be producing the results you are getting.

    2. If you want to enforce that only one category is “searched” for related events, this may be possible by adding a filter like the following to your theme’s functions.php file:


    if ( class_exists( 'Tribe__Events__Main' ) ) {
    /**
    * Rework the related events tax_query.
    *
    * @param array $args
    * @return array
    */
    function tribe_limit_related_posts_args_to_one_cat( $args ) {

    if ( ! is_array( $args ) || empty( $args ) ) {
    return $args;
    }

    // Remove the default tax_query;
    unset( $args['tax_query'] );

    $args['tax_query'][] = array(
    'taxonomy' => Tribe__Events__Main::TAXONOMY,
    'field' => 'slug',
    'terms' => array( 'barbecue' ),
    );

    return $args;
    }

    add_filter( 'tribe_related_posts_args', 'tribe_limit_related_posts_args_to_one_cat' );
    }

    ☝️ Something like this would reduce the searchable event categories to just the event category whose slug is “barbecue”.

    We are not generally able to help with writing custom code like I did above, so you may need to further tinker and refine that code, but let me know if this helps or is even addressing the problem you described here.

    Thank you!
    George

    #1150583
    Support Droid
    Keymaster

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

Viewing 3 posts - 1 through 3 (of 3 total)
  • The topic ‘Can the Related Events be associated with a particular category?’ is closed to new replies.