Tell me more ×
WordPress Answers is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I have blog posts each having 3 or more categories. The issue is that i need to search related posts to a post and i have to match at least 2 categories i.e. there must be 2 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 1 category. Thanks for your help.

share|improve this question
something related wordpress.org/support/topic/… – panky1986 Aug 14 '12 at 6:07

1 Answer

Perhaps try using 'category__and' instead?

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

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

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.