Support » Themes and Templates » query posts using array, not pulling in child category posts

  • Hello, Im using <?php query_posts(array('category__and'=>array(9763, 9751))); ?> where 9763 is category “A” and 9751 is category “B” which has many child categories.

    I would like to pull in all posts that are part of cat A and cat B (or all A and child of B)

    Issue is that any posts that are not directly in B but are only a child of B do not appear.

Viewing 1 replies (of 1 total)
  • Codes explains that category__and will not pull in child categories

    Multiple Category Handling

    Display posts that are in multiple categories. This shows posts that are in both categories 2 and 6:

    $query = new WP_Query( array( ‘category__and’ => array( 2, 6 ) ) );

    To display posts from either category 2 OR 6, you could use cat as mentioned above, or by using category__in (note this does not show posts from any children of these categories):

    One approach is select all 9763 posts using get_posts. This puts them in an array. Then loop through the array, selecting posts that are in 9751 or its child categories. (First make an array of all the child categories of 9751) It requires some custom code. I googled looking for an article for you to copy but didn’t find one.

Viewing 1 replies (of 1 total)
  • The topic ‘query posts using array, not pulling in child category posts’ is closed to new replies.