WordPress Related Post by tags in Single.php

Please i want to create a related post In my site, but this code shows only related post of post that has only first tag, pls i want a related to select all the tags (Because my site is a blog and each post can have upto 5tags).

I want to show related update base on first tag and then other tags too.

Below is the code i got, but its working either ways…

Thanks in advance.

ID);
if ($tags) {
echo ‘Related Posts’;
$first_tag = $tags[0]->term_id;
$args=array(
‘tag__in’ => array($first_tag),
‘post__not_in’ => array($post->ID),
‘posts_per_page’=>5,
‘caller_get_posts’=>1
);
$my_query = new WP_Query($args);
if( $my_query->have_posts() ) {
while ($my_query->have_posts()) : $my_query->the_post(); ?>
” rel=”bookmark” title=”Permanent Link to “>

Hope in understood…???

Read more here:: WordPress Related Post by tags in Single.php

Leave a Reply

Your email address will not be published. Required fields are marked *