tribe_get_related_posts( int $count = 3, int|obj $post = false )

Template tag to get related posts for the current post.


Parameters

$count

(int) (Optional) number of related posts to return.

Default value: 3

$post

(int|obj) (Optional) the post to get related posts to, defaults to current global $post

Default value: false


Top ↑

Return

(array) the related posts.


Top ↑

Source

File: src/functions/template-tags/general.php

	function tribe_get_related_posts( $count = 3, $post = false ) {
		$post_id = Tribe__Events__Main::postIdHelper( $post );

		$args = [
			'posts_per_page' => $count,
			'start_date' => 'now',
		];
		$posts = [];

		$orm_args = tribe_events()->filter_by_related_to( $post_id );

		if ( $orm_args ) {
			$args = array_merge( $args, $orm_args );

			if ( $args ) {
				$posts = tribe_get_events( $args );
			}
		}

		/**
		 * Filter the related posts for the current post.
		 *
		 * @param array $posts   The related posts.
		 * @param int   $post_id Current Post ID.
		 * @param array $args    Query arguments.
		 *
		 * @since 3.2
		 */
		return apply_filters( 'tribe_get_related_posts', $posts, $post_id, $args );
	}