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:
$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?
First, don’t use
query_posts
. Ever.Then, using
get_posts
, you can use thecategory__and
parameter:Can you try this one?