My problem is quite simple:
I've got a couple of posts in different categories that have several tags, some of them in common.
When I load a post, in my sidebar (using PHP Code) I want to show a list of all the posts of another category that share the same tags as the one displayed.
I've tried related posts and it doesn't do the trick, because I found no way of adding the 'only this category' condition.
UPDATE. I have tried this
<?php
global $post;
$tagargs = $catargs= '';
$catnames ='';
$tagnames = '';
$tags = get_the_tags($id);
if ($tags) {
foreach ($tags as $tag) {
$tagnames .= $tag->name . ',';
}
$tagargs = array(
'ignore_sticky_posts' => 1,
'tag' => $tagnames,
'post__not_in' => array($id),
'showposts' => $number,
'orderby' => 'name',
'order' => 'asc',
'cat' => '152'
);
}
$posts = get_posts($tagargs);
foreach($posts as $post) :
?>
<li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
<?php endforeach; ?>
And I get all the posts in category 152 (the one I want) but that have only in common the first tag. I have figured out how to do the opposite, I mean, first, get the tags of all the posts inside this category (152) and then compare them with those in the current post (because sometimes, the current post have more than two or three), and get those posts that have all the tags in both sides. What do you think?