Title: Behavior comment/suggestion
Last modified: August 22, 2016

---

# Behavior comment/suggestion

 *  Resolved [morgentau](https://wordpress.org/support/users/morgentau/)
 * (@morgentau)
 * [11 years, 2 months ago](https://wordpress.org/support/topic/behavior-commentsuggestion/)
 * Hi,
 * I’m using the plugin in a template with km_rpbt_related_posts_by_taxonomy().
 * I added a term ID to the exclude_terms option, and for several minutes I was 
   trying to understand why a post which I know has that ID kept appearing in the
   results.
 * Then I saw that the two posts shared another common term, which explained everything.
 * However, it seems to me to be counterintuitive. When you ask for posts with common
   terms but you ask to exclude a specific, other term, you would expect the function
   not to return posts which have that term associated with them, regardless of 
   other common terms.
 * It’s like saying e.g. “See a list of other cities which are large and european,
   but which are not capitals”. By excluding “capital” you’d hope to not see them,
   even though they might have “large” and “european” in common.
 * At least that’s what I was expecting…
 * Great stuff nonetheless.
 * [https://wordpress.org/plugins/related-posts-by-taxonomy/](https://wordpress.org/plugins/related-posts-by-taxonomy/)

Viewing 4 replies - 1 through 4 (of 4 total)

 *  Plugin Author [keesiemeijer](https://wordpress.org/support/users/keesiemeijer/)
 * (@keesiemeijer)
 * [11 years, 2 months ago](https://wordpress.org/support/topic/behavior-commentsuggestion/#post-5941721)
 * Hi morgentau.
 * If you need to totally exclude posts that have the excluded terms see this code
   example:
    [https://keesiemeijer.wordpress.com/related-posts-by-taxonomy/recipes/#excluding_terms](https://keesiemeijer.wordpress.com/related-posts-by-taxonomy/recipes/#excluding_terms)
 *  Thread Starter [morgentau](https://wordpress.org/support/users/morgentau/)
 * (@morgentau)
 * [11 years, 2 months ago](https://wordpress.org/support/topic/behavior-commentsuggestion/#post-5941888)
 * Thank you! I’m trying to understand why the “exclude” function needs to be that
   long with all the validation and custom SQL query. Excuse me because I’m not 
   a developer, but isn’t it possible to simply use ‘tax_query’ instead?
 * e.g. here:
 * [http://www.webdevdoor.com/wordpress/get-posts-custom-taxonomies-terms/](http://www.webdevdoor.com/wordpress/get-posts-custom-taxonomies-terms/)
 * Thanks.
 *  Plugin Author [keesiemeijer](https://wordpress.org/support/users/keesiemeijer/)
 * (@keesiemeijer)
 * [11 years, 2 months ago](https://wordpress.org/support/topic/behavior-commentsuggestion/#post-5941894)
 * Yes, use a tax query to get all the posts with the excluded term ids and add 
   them to the ‘exclude_posts’ parameter of the km_rpbt_related_posts_by_taxonomy()
   function.
 * Example [untested]
 *     ```
       $args = array(
       	'fields' => 'ids',
       	'posts_per_page' => -1,
   
       	// example tax query
       	'tax_query' => array(
       		array(
       			'taxonomy' => 'category',
       			'field'    => 'id',
       			'terms'    => array( 22, 88 ),
       		),
       	),
       );
       $posts = get_posts( $args );
   
       $args = array();
   
       if ( !empty( $posts ) ) {
       	$args['exclude_posts'] = $posts;
       }
   
       $related_posts = km_rpbt_related_posts_by_taxonomy( $post->ID, 'category', $args  );
       ```
   
 * The code I linked to is if you want this for the shortcode or widget and is quite
   small compared to the get_posts() function used by WordPress 😉
 *  Thread Starter [morgentau](https://wordpress.org/support/users/morgentau/)
 * (@morgentau)
 * [11 years, 2 months ago](https://wordpress.org/support/topic/behavior-commentsuggestion/#post-5941897)
 * I’ll try this as soon as I can. Thanks very much again for your support.

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘Behavior comment/suggestion’ is closed to new replies.

 * ![](https://ps.w.org/related-posts-by-taxonomy/assets/icon.svg?rev=1115231)
 * [Related Posts by Taxonomy](https://wordpress.org/plugins/related-posts-by-taxonomy/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/related-posts-by-taxonomy/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/related-posts-by-taxonomy/)
 * [Active Topics](https://wordpress.org/support/plugin/related-posts-by-taxonomy/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/related-posts-by-taxonomy/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/related-posts-by-taxonomy/reviews/)

 * 4 replies
 * 2 participants
 * Last reply from: [morgentau](https://wordpress.org/support/users/morgentau/)
 * Last activity: [11 years, 2 months ago](https://wordpress.org/support/topic/behavior-commentsuggestion/#post-5941897)
 * Status: resolved