I have multiple users adding content to restricted categories (using RoleScoper) in my WordPress setup that don’t show up on the homepage (custom template with query_posts()
).
I’m looking for a way to “promote” the submitted content to the homepage by adding it to another category.
My loop code looks like this:
<?php
query_posts($query_string . '&cat=-37');
if (have_posts()):
while (have_posts()): the_post(); ?>
This will exclude all posts in category 37. However, even if I add the post to a different category it still gets excluded.
Is there a way to exclude a post if it belongs to just that one category?
There is no simple way to do this via
WP_Query()
. Depending how many categories you have, the following may not be a good idea. If you have ~20 you may be ok. So, instead of saying “all posts excluding ones in 37”, you would do “get me everything in all terms (not specifying term_id 37”).To do this you need to use a
category__in
for all your other categories:This will get you all posts that are in a category other than/aswel as 37. However, doing this on a large amount of categories will start to slow the query down (I am thinking +40,000 posts for example).