Reputation: 22941
I was wondering how I can query posts that are not in a certain category.
I tried
query_posts('post_status=publish&post_type=post&category!=books&offset=5');
So I'm trying to get all published posts that are not in the category books, and then I have an offset of 5.
Thanks, Matt Mueller
Upvotes: 0
Views: 2240
Reputation: 2220
You need to use -{$category_id}
$cat = get_category_by_slug('category');
query_posts("cat=-{$cat->term_id}&offset=5");
Upvotes: 3
Reputation: 33833
The WordPress documentation for query_posts
is very thorough: Template Tags/query posts:
Exclude Posts Belonging to Only One Category:
Show all posts except those from a category by prefixing its ID with a '-' (minus) sign.
query_posts('cat=-3');
You can also exclude multiple categories this way:
query_posts(array('category__not_in' => array(2,6)));
Upvotes: 3