Get posts that have both of two categories only

I added a post in wordpress and selected two categories (e.g: id=20,150).
Now with a custom query_post method, I want to show the post only if it have both of the categories.

For this I wrote this query:

Read More
$subc = array('20','150');
$query = query_posts('post_type=post&cat='.$subc.'&post_status=publish&posts_per_page=50&paged='. get_query_var('paged'));

The query should be treate this way: if categories found are 20 AND 150 then show, otherwise don’t display.

But I am not getting exactly what i want. Can anyone modify above query and help me to show exactly what I want?

Related posts

2 comments

  1. Can you try this one?

    query_posts(array(
      'post_type'=>'post',
      'cat'=>'20,150',
      'post_status'=>'publish',
      'posts_per_page'=>'50',
      'paged'=>get_query_var('paged')
    ));
    

Comments are closed.