I have a WP blog with a list of categories. I have specific template which is applied to a category called “News” which is all fine and working, but now I need to make sure that the posts in this category are not included in the main blog. I’ve tried a few bits and it hasn’t worked out for me. Anyone any suggestions?
As I’m working off a dev/test/prod environment which were all set up by different people (… le sigh…) the same categories all have different id’s so I was hoping to do it off the category name.
Cheers,
T
Thanks for that Giannis. I knew I could do it with the query_posts negative category type. Thanks for putting me on the right track though.
I have to work this off the category name, that’s the only provision of this query. So to do this, I got the category id from the name:
Put this at the top of the loop.php and solved my problem.
Thanks again everyone, love Stackoverflow!
Excluding a category from the loop is quite simple, you just need to pass the category ID as a parameter, for example to exclude categories with id 3 and 8:
In your case, it is not possible to exclude a category by its name (category_name parameter).
You can also try using a plugin if that’s easier for the multiple environment situation:
http://wordpress.org/extend/plugins/simply-exclude/
I did it completely differenly, and using slugs only, as such:
Note that there exists an array entry, called tax_query, which also containts another array that containts a parameters called operator, and this operator has a value of NOT IN, which will exclude the values in the term field as opposed to including them.
IMPORTANT NOTE: Please be advised that if a post has two taxonomy terms, and one of those terms is in the list of terms to exclude, then this will not be part of the result.
For more details, read here: http://codex.wordpress.org/Class_Reference/WP_Query