I am working on this code to show my related by any tag posts, but its showing me thumbnail as a link twice for posts with the same tag.
How can i force this to show related post only once?
If you have >=2 post with 2 the same tags you will get doubled values
<?php
global $post;
$nextTagThumb='-1';
$tags = wp_get_post_tags($post->ID);
foreach ($tags as $tag) :
?>
<?php
if ($tags) {
$what_tag = $tags[($nextTagThumb+'1')]->term_id;
$args=array(
'tag__in' => array($what_tag),
'post__not_in' => array($post->ID),
'showposts'=>100,
'ignore_sticky_posts'=>1
);
$my_query = new WP_Query($args);
if( $my_query->have_posts() ) {
while ($my_query->have_posts()) : $my_query->the_post();
?>
<li>
<a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>">
<?php the_post_thumbnail(); ?>
</a>
</li>
<?php
endwhile;
}
wp_reset_query();
$nextTagThumb = ($nextTagThumb+1);
}
?>
<?php endforeach; ?>