Home › Forums › Calendar Products › Events Calendar PRO › Related Events
- This topic has 4 replies, 3 voices, and was last updated 10 years, 10 months ago by
Support Droid.
-
AuthorPosts
-
June 5, 2015 at 2:01 pm #967534
Michael McFann
ParticipantWhere can I find an explanation of how related events works? I do not see any fields that would seem to indicate they are used for this function. All I see is a way to turn on/off the display of related events.
Thanks – Michael
June 7, 2015 at 12:37 pm #967697Brian
MemberHi Michael,
The related events look for events with the same tags and/or categories.
We use the wp_get_post_tags and wp_get_object_terms to get tags and categories of the current events
Then we use those and the orderby random argument to find related events.
Here is the entire function in 3.10:
/**
* Template tag to get related posts for the current post.
*
* @param int $count number of related posts to return.
* @param int|obj $post the post to get related posts to, defaults to current global $post
*
* @return array the related posts.
*/
function tribe_get_related_posts( $count = 3, $post = false ) {
$post_id = Tribe__Events__Main::postIdHelper( $post );
$tags = wp_get_post_tags( $post_id, array( 'fields' => 'ids' ) );
$categories = wp_get_object_terms( $post_id, Tribe__Events__Main::TAXONOMY, array( 'fields' => 'ids' ) );
if ( ! $tags && ! $categories ) {
return;
}
$args = array(
'posts_per_page' => $count,
'post__not_in' => array( $post_id ),
'eventDisplay' => 'list',
'tax_query' => array('relation' => 'OR'),
'orderby' => 'rand',
);
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
);
}$args = apply_filters( 'tribe_related_posts_args', $args );
if ( $args ) {
$posts = Tribe__Events__Query::getEvents( $args );
} else {
$posts = array();
}return apply_filters( 'tribe_get_related_posts', $posts ) ;
}Let me know if you have any follow up questions.
Thanks
June 14, 2015 at 11:21 am #969301Michael McFann
ParticipantThanks for that info.
We are using the The Events Calendar Category Colors so we are wondering if there is a way to remove the use of categories for related events and just use tags?
Thanks – Michael
June 15, 2015 at 7:38 am #969422Brian
MemberHi,
The only way to remove the event categories would be to replace that function ( tribe_get_related_posts() ) with your own and then put that into the Event Templates following our themer’s guide:
https://theeventscalendar.com/knowledgebase/themers-guide/
So you could take that function, add it to your theme’s functions.php, rename it. Then remove the category part of the function and add it in place of the current related events function.
That function is called on this template:
events-pro\src\views\pro\related-events.php
In 3.9 the template is here:
events-pro\views\pro\related-events.php
All you have to do is change the name of the function here to what you call it:
$posts = tribe_get_related_posts();
Cheers
July 7, 2015 at 6:32 am #984322Support Droid
KeymasterThis 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 ‘Related Events’ is closed to new replies.
