Related Events Are Not Related

Home Forums Calendar Products Community Events Related Events Are Not Related

Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #1088530
    dcantato
    Participant

    I was looking at the related events and realized they are not related at all to the event shown. I read through the documentation and it said it relies on tags and categories.

    So I went in and added tags to a group of events. Loaded one up and it is still random.

    Does related events default to category before tags? Can I change that?

    All of my events for the moment are in the same category.

    Also is it possible to do related events by location? That would seem like the most relatable events.

    #1088790
    George
    Participant

    Hey @dcantato,

    I’m sorry to hear that your “related events” results are sub-par. Tags and categories are weighed equally by the function that loads related events, but if you would like to change the function at all, you can indeed do this.

    Modifying the function OR adding location-based relationships are both, unfortunately, code customizations. I say “unfortunately” because we cannot help with code customizations. Check out “product support” on this page for more information about that → http://theeventscalendar.com/terms

    That being said, there are two filters you can use:
    • tribe_related_posts_args
    • tribe_get_related_posts

    These are quite powerful on their own and I hope you find them useful. To learn more about these filters, and about the function that gets related posts in general, then head to this file in your plugin files for Events Calendar Pro:

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

    The function to look for is called tribe_get_related_posts().

    I hope this information helps. Best of luck with your customizing!

    – George

    #1092512
    dcantato
    Participant

    If I took out the categories part of the if statement would it rely on the tags only?

    	if ( $tags ) {
    			$args['tax_query'][] = array( 'taxonomy' => 'post_tag', 'field' => 'id', 'terms' => $tags );
    		}
    		if ( $categories ) {
    			$args['tax_query'][] = array(
    				'taxonomy' => Tribe__Events__Main::TAXONOMY,
    				'field'    => 'id',
    				'terms'    => $categories,
    			);
    		}
    #1092686
    George
    Participant

    Hey @dcantato,

    That indeed may work—try it out on your site firsthand and see what happens!

    We cannot help with customizations, @dcantato, so for any further code-related questions you will have to take the reins on tinkering, learning, and seeing what works.

    Please read this page to learn more about the type of support we can provide → https://theeventscalendar.com/knowledgebase/what-support-is-provided-for-license-holders/

    Thank you,
    George


    PS

    So while everything I wrote above is true, I still wanted to help you resolve this. You ask about removing categories by removing the OR statement; this unfortunately won’t quite do the job, and to hopefully save you time, I have just gone ahead and written a snippet for you. 😉 Please read it and try to see how it works, I hope you can learn from it!

    To use the snippet, first remove all other custom coding you’ve done so far to try and achieve this.

    Once that’s gone, add the following code to your theme’s functions.php file:

    /**
    * FORCE the "Related Events" section to only to look in tags for relationship.
    *
    * @link http://m.tri.be/192k
    */
    add_filter( 'tribe_related_posts_args', 'tribe_force_tags_for_related_events' );

    function tribe_force_tags_for_related_events( $args ) {

    if ( ! is_array( $args['tax_query'] ) )
    return $args;

    foreach ( $args['tax_query'] as $key => $arg ) {
    if ( ! empty( $args['tax_query'][ $key ]['taxonomy'] ) ) {

    if ( 'tribe_events_cat' === $args['tax_query'][ $key ]['taxonomy'] )
    unset( $args['tax_query'][ $key ] );
    }
    }

    return $args;
    }

    That works well for me and should reduce the search for similar events to ONLY look for tags—not categories, no matter what.

    Cheers

    #1092884
    dcantato
    Participant

    I’ll give this a try soon, thanks for the added support!

    #1092950
    George
    Participant

    🙂

    #1099623
    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 7 posts - 1 through 7 (of 7 total)
  • The topic ‘Related Events Are Not Related’ is closed to new replies.