Excluding sub-categories from WP_Query
-
I have a dozen or so different category templates for the different sections of my site, and am trying to exclude a few categories from one of them.
Here’s my loop:
<?php $my_query = new WP_Query($query_string . "&cat=107,108,109,110&posts_per_page=16"); while ($my_query->have_posts()) : $my_query->the_post(); $wp_query->in_the_loop = true; if ( $post->ID == $do_not_duplicate ) continue; update_post_caches($posts); $do_not_duplicate = $post->ID; ?>
I’ve tried everything I could find/think of to either only include the four categories you see in the loop above (cat=107,108….) or exclude the others (cat=-112,-113…). Neither method seems to do anything, and I’m now thinking it’s because all the categories are sub-categories of a main one, 105 in my case.
Can you not exclude or only include sub-categories in a wp_query? Or is there another way to go about this?
Thanks guys.
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
- The topic ‘Excluding sub-categories from WP_Query’ is closed to new replies.