Using widget, not finding matching posts, stops at certain date?
-
Hi. I have two posts with the same exact tags. One post showed up as a related post (in first place) on one page and the other didn’t. It wasn’t until I moved the oldest post up to this year’s date (it was post dated last year) that it “found” the related post.
Is the plugin searching far back enough for related posts? or does it stop looking for related posts at a certain date? I’m using the widget by the way, with a custom code. Is there any way to have it search through the entire database of posts for related posts?
Here is the code I’m using:
/** * Filter used by the Related Posts by Taxonomy plugin. */ add_filter( 'related_posts_by_taxonomy_widget_args', 'rpbt_return_all_posts', 10, 2 ); function rpbt_return_all_posts( $args, $instance ) { $args['_posts_per_page'] = $args['posts_per_page']; $args['posts_per_page'] = -1; return $args; } /** * Filter used by the Related Posts by Taxonomy plugin. */ add_filter( 'related_posts_by_taxonomy', 'rpbt_add_percentage', 10, 4 ); /** * Adds percentage to related post objects. */ function rpbt_add_percentage( $related_posts, $post_id, $taxonomies, $args ) { $related_posts = array_reverse( $related_posts ); $terms = count( $args['related_terms'] ); $order = array(); foreach ( $related_posts as $key => $post ) { $related_terms = wp_get_object_terms( $post->ID, $taxonomies, array( 'fields' => 'ids' ) ); $related_terms = count( $related_terms ); $percentage = 0; if ( isset( $post->termcount ) ) { $percentage = round( ( ( $post->termcount / $related_terms ) * 100 ) ); if ( $terms > $related_terms ) { $percentage = round( ( ( $post->termcount / $terms ) * 100 ) ); } } $order[ $key ] = $percentage; $related_posts[ $key ]->percentage = $percentage; } // sort the posts by percentage array_multisort( $order, SORT_DESC, $related_posts ); if ( isset( $args['_posts_per_page'] ) ) { $related_posts = array_slice( $related_posts, 0, $args['_posts_per_page'] ); } return $related_posts; } /** * Filter used by the Related Posts by Taxonomy plugin. */ add_filter( 'related_posts_by_taxonomy_caption', 'rpbt_add_in_common_percentage', 10, 3 ); /** * Adds the percentage to thumbnail captions. */ function rpbt_add_in_common_percentage( $caption, $post, $args ) { if ( isset( $post->percentage ) ) { $caption .= ' (' . $post->percentage . '%)' ; } return $caption; }Also, I am using the latest version of the plugin.
The topic ‘Using widget, not finding matching posts, stops at certain date?’ is closed to new replies.