Note that there are some explanatory texts on larger screens.

plurals
  1. POWordpress - related posts by custom taxonomy problem
    primarykey
    data
    text
    <p>I'm trying to display related posts based on a custum taxonomy. I found a query at wordpress.org that kind of works. However the original post gets duplicated in the results multiple times. (words is the name of the custom taxonomy I use) What seems to happen is that the single post gets duplicated according to what amount showpost is set. Any idea's what could cause this?</p> <p>The code:</p> <pre><code>&lt;?php //for in the loop, display all "content", regardless of post_type, //that have the same custom taxonomy (e.g. words) terms as the current post $backup = $post; // backup the current object $found_none = '&lt;h2&gt;No related posts found!&lt;/h2&gt;'; $taxonomy = 'words';// e.g. post_tag, category, custom taxonomy $param_type = 'words'; // e.g. tag__in, category__in, but genre__in will NOT work $post_types = get_post_types( array('public' =&gt; true), 'names' ); $tax_args=array('orderby' =&gt; 'none'); $tags = wp_get_post_terms( $post-&gt;ID , $taxonomy, $tax_args); if ($tags) { foreach ($tags as $tag) { $args=array( "$param_type" =&gt; $tag-&gt;slug, 'post__not_in' =&gt; array($post-&gt;ID), 'post_type' =&gt; $post_types, 'showposts'=&gt;5, 'caller_get_posts'=&gt;1 ); $my_query = null; $my_query = new WP_Query($args); if( $my_query-&gt;have_posts() ) { while ($my_query-&gt;have_posts()) : $my_query-&gt;the_post(); ?&gt; &lt;h3&gt;&lt;a href="&lt;?php the_permalink() ?&gt;" rel="bookmark" title="&lt;?php the_title(); ?&gt;"&gt;&lt;?php the_title(); ?&gt;&lt;/a&gt;&lt;/h3&gt; &lt;?php $found_none = ''; endwhile; } } } if ($found_none) { echo $found_none; } $post = $backup; // copy it back wp_reset_query(); // to use the original query again ?&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload