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 want a QueryLoop that exclude some categories and its subcategories,

I have this:

        $args = array(
            'category__not_in' => array( 2, 6 ),
        );

this exclude the categories, 2 and 6 , but no its subcategories, what can I do?

====== Update ======= This is what I did, but now I'm searching for a better solution:

        $excludes = array(2,6);
        $ex_childs = array();

        foreach($excludes as $exclude){
             $a = get_categories('child_of='.$exclude);
            foreach($a as $key => $value){
                $ex_childs[] =  $value->cat_ID;
            }
        }           

        $all_excludes = array_merge($excludes, $ex_childs);

        $args = array(
            'category__not_in' => $all_excludes
        );
share|improve this question

1 Answer 1

up vote 0 down vote accepted

How about something like this where you filter the posts once the WP_Query gets them?

share|improve this answer
    
Thanks, I already did something similar, but now I'm searching for a better solution, –  eveevans Jan 16 '12 at 21:42

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.