title: Exclude all sub categories from wp_query
body: <p>I've been searching high and low for and answer to this, but I'm not actually sure it's possible!</p>
  
  <p>I have a WP_Query that pulls posts from almost everything, however, I wish to exclude a specific category and/or all it's sub categories.</p>
  
  <p>Searching around people are yet to find a solution for this.</p>
  
  <p>Here's my query so far:</p>
  
  <pre><code>$args = array(
      'post_type' =&gt; 'sell_media_item',
      'cat' =&gt; -98,
      'orderby' =&gt; 'desc',
      'paged' =&gt; $paged,
      'posts_per_page' =&gt; 20
  ); ?&gt;
  
  &lt;?php $loop = new WP_Query( $args ); ?&gt;
  </code></pre>
  
  <p>I thought just excluding <code>cat 98</code> would grab all the sub categories too, but apparently not.</p>
  
  <p>I've tried using:</p>
  
  <p><code>category__not_in</code>, <code>depth=0</code>, <code>parent=0</code> and even <a href="http://wordpress.org/support/topic/how-to-exclude-all-child-categories-of-a-category-from-showing-up-in-the-loop" rel="nofollow">an adaptation of this</a>, with no luck.</p>
  
  <p>Any ideas?</p>
  
  <p>[EDIT]
  I'm using a custom taxonomy called Collections, so putting <code>'collection' =&gt; 'vip'</code> into the query means it will only show this collection. I'm thinking if there's a way of reversing this so it excludes the collection instead?</p>
  
  <p>As it's not possible to list all of the categories that will appear here as they will be changing all of the time.</p>
  
  <p>[EDIT 2]
  After the discussion in the comments below, here's the updated code.</p>
  
  <pre><code>$ex = array(
      'taxonomy' =&gt; 'collection',
      'child_of' =&gt; 98,
      'hide_empty' =&gt; 0
  );
  $categories = get_categories($ex);
  
  $categoriesToExclude = array();
  foreach ($categories as $category) {
      $categoriesToExclude[] = $category-&gt;cat_ID;
  }
  
  echo('&lt;pre&gt;'); var_dump($categories);
  
  
  $args = array(
      'post_type' =&gt; 'sell_media_item',
      'category__not_in' =&gt; $categoriesToExclude,
      'orderby' =&gt; 'desc',
      'paged' =&gt; $paged,
      'posts_per_page' =&gt; 20
  ); ?&gt;
  
  &lt;?php echo('&lt;br /&gt;&lt;pre&gt;'); var_dump($args); ?&gt;
  
  &lt;?php $loop = new WP_Query( $args ); ?&gt;
  </code></pre>