Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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?

share|improve this question

migrated from webmasters.stackexchange.com May 11 '11 at 1:37

This question came from our site for pro webmasters.

    
Are those posts in category 37 and the other category or just the other category and not showing up still? –  kel Feb 9 '11 at 22:45
    
Are those posts in category 37 and the other category or just the other category and not showing up still? –  kel Feb 9 '11 at 22:45
    
Is there an admin that can move this over there for me? –  sirlancelot Feb 14 '11 at 19:44
    
This does not provide an answer to the question. To critique or request clarification from an author, leave a comment below their post. –  Brian Fegter Aug 28 '12 at 2:52

1 Answer 1

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:

// Get all the category IDs (except 37)
$categories = get_terms( 'category', array( 'exclude' => array( 37 ), 'fields' => 'ids' ) );

query_posts( array( 'category__in' => $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).

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.