What I'm trying to do: Have a script that will go trough every taxonomy of a custom post type, then list the posts that are with that taxonomy.


<?php $taxos = get_categories( 'taxonomy='.$taxonomy.'&post_type='.$type.'&orderby=term_group' ); ?>
<?php if($taxos) : foreach($taxos as $taxoOnglet) : ?>

    $ongletQuery = new WP_Query(array(
        'post_type' => $type,
        $taxonomy => $taxoOnglet->slug,
        'showposts' => -1,
        'orderby'   => 'menu_order',
        'order'     => 'ASC',

[...]loop for showing the posts[...]

<?php endif; ?>
<?php wp_reset_query(); ?>

I do get all my posts with that query fine, but there is a problem. The parent taxonomies list their children's posts, even if the post is only attributed to the children.

Which gives me something like this

Post A
Post B

Post A

Post B

So I'm trying to find a way to remove the A and B posts from the parent taxonomy, so they will only appear in the child where they are attributed. Is there a way to do this with the WP_Query of WP?


You may well be able to do this with the taxonomy query parameter you can pass to the WP_Query object. You'll find it on the codex, look for include_children. Sadly I'm short on time or else I'd try and put some code together to help out more...

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.