I workout wordpress related post by category.
my problem is I don’t want to display the item in current post in the related post.

for example: i have list of item belong to color category which is red, blue, green, black and red is my current page, I don’t want red appear in Related post

<?php foreach((get_the_category()) as $category) {$id = $category->cat_ID;} ?>
     <ul class="recentWorks">
            if (have_posts()) : {
            $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
            query_posts("&cat={echo $id;}&showposts=6&paged=$paged&order=ASC");
            while(have_posts()) : the_post();
            <a class="imageHover" href="<?php the_permalink(); ?>" id="post-<?php the_ID(); ?>"><?php the_title(); ?></a>
            <?php if ( has_post_thumbnail()) the_post_thumbnail('post-thumbnails'); ?>
            <span><?php the_title(); ?></span>
          <?php endwhile; ?>
         <?php endif; ?>

Read more here: Related post by category: {if id = to current page id} should not display in related post


If you know the solution of this issue, please leave us a reply in Comment section, to update the question.

Related Wordpress search:

, , , , ,

Wordpress related questions and answers: