2

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?

4
  • 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. Aug 28 '12 at 2:52
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).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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