Home › Forums › Calendar Products › Events Calendar PRO › Can the Related Events be associated with a particular category?
- This topic has 3 replies, 4 voices, and was last updated 7 years, 8 months ago by brucewgresham.
-
AuthorPosts
-
July 20, 2016 at 11:04 am #1142059brucewgreshamParticipant
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
July 20, 2016 at 12:04 pm #1142083GeorgeParticipantHey 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!
GeorgeAugust 11, 2016 at 9:35 am #1150583Support 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 ‘Can the Related Events be associated with a particular category?’ is closed to new replies.