• Resolved morgentau

    (@morgentau)


    Hi,

    I’ve found your plugin through the WordPress forums and I’d first like to say thank you for sharing it with the community. I’ve been looking for precisely this functionality and your plugin is fast and very easy to use.

    I’m using it in the template only, no shortcodes or widgets, using “km_rpbt_related_posts_by_taxonomy” (which BTW isn’t clearly mentioned in the main page of the documentation).

    I was wondering if there was an option to reverse the output of the function, i.e. make it returns posts which have the fewest (or no) common tags with the current post.

    Thank you very much.

    https://www.ads-software.com/plugins/related-posts-by-taxonomy/

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author keesiemeijer

    (@keesiemeijer)

    Hi morgentau.

    The related posts should have at least one term in common. Otherwise what is the point of the plugin ??

    Have you tried with 'order' => 'ASC'.

    The only thing you can do without editing plugin files is to get all the related posts and use the php function array_reverse().
    https://php.net/manual/en/function.array-reverse.php

    Here is an example.

    <?php
    
    // check if the function exists
    if ( function_exists( 'km_rpbt_related_posts_by_taxonomy' ) ) {
    
    	$args = array(
    		'posts_per_page' => -1,
    	);
    
    	$taxonomies = array( 'category', 'post_tag' );
    
    	// get the related posts
    	$related_posts = km_rpbt_related_posts_by_taxonomy( $post->ID, $taxonomies, $args );
    
    	// reverse the related posts
    	$related_posts = array_reverse( $related_posts );
    
    	// use first 5 related posts
    	$related_posts = array_slice( $related_posts, 0, 5 );
    
    	if ( $related_posts ) {
    
    		echo '<h2>Related Posts</h2>';
    		echo '<ul>';
    
    		// Loop through the related posts.
    		foreach ( (array) $related_posts as $related ) {
    
    			echo '<li><a href="' . get_permalink( $related->ID ) . '">' . $related->post_title . '</a></li>';
    		}
    
    		echo '</ul>';
    	}
    }
    ?>

    Thread Starter morgentau

    (@morgentau)

    OK, thank you very much for this example.

    In a future update maybe? This plugin is extremely useful.

    Cheers.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Can functionality be inverted?’ is closed to new replies.