tags:

views:

67

answers:

2

Hey all,

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

+2  A: 

You need to use -{$category_id}

$cat = get_category_by_slug('category');
query_posts("cat=-{$cat->term_id}&offset=5");
nickohrn
That's perfect! Thanks man!
Matt
Oh I should add.. It should be 'cat=-...', just a minor issue.
Matt
Fixed. Sorry about that. I was in a bit of a rush.
nickohrn
+1  A: 

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)));

artlung