I have blog posts each having three or more categories.

The issue is that I need to search related posts and I have to match at least two categories i.e. there must be two common categories. I am using this query:

   $args = wp_parse_args($args, array(
    'showposts' => 10,
    'post__not_in' => array($post_id),
    'ignore_sticky_posts' => 1,
    'category__in' => wp_get_post_categories($post->ID)
));
    $query = new WP_Query($args);

I am trying category__in but it gives all posts which match even just one category.

1 Answer
1

Perhaps try using ‘category__and’ instead?

E.g. ‘category__and’ => array(1,3)

http://codex.wordpress.org/Function_Reference/query_posts

Tags:

Leave a Reply

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