related-posts-by-taxonomy icon indicating copy to clipboard operation
related-posts-by-taxonomy copied to clipboard

Related Posts Returning Based on Just 1 Common Taxonomy Instead of Number of Relate Taxonomy.

Open timnolte opened this issue 5 years ago • 2 comments

I am calling the following code:

km_rpbt_get_related_posts(
	$post->ID,
	array(
		'post_types'     => $related_post_types, // array 
		'taxonomies'     => $related_taxonomies,
		'exclude_posts'  => $exclude_posts,
		'limit_posts'    => $limit,
		'posts_per_page' => $limit, // Get all the results based on the limit.
		'fields'         => 'ids',
	)
)

Where I am using arrays of multiple post types and a single taxonomy, the post_tags taxonomy. The problem I'm seeing is that posts type that have more than one tag in common are not being returned as a priority. I get records first that have only 1 tags that is the same. Basically, contrary to the documentation, "Posts with the most terms in common will display at the top!" is not happening.

timnolte avatar Jul 14 '20 21:07 timnolte

Just for testing try it without exclude_posts and setting posts_per_page to -1. Do the posts with multiple related tags show up in the list of related posts (but in the wrong order)?

And use post_tag if you're using the tags taxonomy.

keesiemeijer avatar Jul 15 '20 12:07 keesiemeijer

@keesiemeijer sorry for the delay. I corrected my issue description. It is post_tags that I'm using. I did some testing and excluding posts doesn't appear to be the issue, if I attempt to set limit_posts to the value of how many posts I need then the sorting doesn't happen. If I exclude limit_posts and just use the posts_per_page to limit how many I get then the sort it working and I get the expected results.

timnolte avatar Jul 29 '20 20:07 timnolte