title: WordPress display only the posts who have a certain parent category
body: <p>I would like to query posts based on specific <code>category_parent id</code>. This is used as a filtering function for the users to filter posts based on a parent category type. I have multiple categories who have multiple children categories. For example, Fruits is the parent category, then children categories can be red, blue, orange. Vegetables is a parent category, and it also has red, blue and orange child categories. I would like users to filter and see all the vegetable child categories or all the fruits child categories. </p>
  
  <p>I am using category id instead of slug in my case. 
  For example, I want to query all the posts whose parent category is 17 and 19. (dummy).</p>
  
  <pre><code>add_action( 'pre_get_posts', 'additional_query', 1, 1);       
  function additional_query( $query ){
       $tax_query = array(
                  array( 
                      "taxonomy" =&gt; "category", 
                      "field" =&gt; 'term_id',
                      "terms" =&gt; array(17, 19)
                  )
              );
              $query-&gt;set( "tax_query", $tax_query );
  }
  </code></pre>
  
  <p>However, when I do <code>get_categories()</code>, the posts returned still contains other categories whose parent is not 17 and 19. 
  How should I approach this problem? Thanks. </p>