I'm trying to show posts from categories A, B, C, D...and Y, except X, unless posts in X are also in Y, then show them with the rest.
I can hide category X on it's own pretty simply:
$args = array( 'post_type' => 'post', 'posts_per_page' => 15, 'paged' => $paged, 'cat' => '-X', );
I've tried to combine two loops, one getting all posts excluding X, the other getting posts that are in both X and Y, but it doesn't seem to work:
$EverythingButXLoop_args = array( 'post_type' => 'post', 'cat' => '-X', ); $EverythingButXLoop = new WP_Query( $EverythingButXLoop_args ); $OnlyXwithYLoop_args = array( 'post_type' => 'post', 'category_name' => 'categoryX+categoryY', ); $OnlyXwithYLoop = new WP_Query( $OnlyXwithYLoop_args ); $mainLoop_args = array( 'posts_per_page' => 15, 'paged' => $paged, ); $mainLoop = new WP_Query( $mainLoop_args ); $mainLoop->posts = array_merge( $EverythingButXLoop->posts, $OnlyXwithYLoop->posts ); //populate post_count count for the loop to work correctly $mainLoop->post_count = $EverythingButXLoop->post_count + $OnlyXwithYLoop->post_count;
I've also thought about getting all category ID's in a var(instead of listing every one of my many other categories) and using it with a category parameter to exclude posts in X...somehow, ie.
'cat' => $categoryIDs, 'category__not_in' => 'X' but I think I'm still just faced with the original problem: excluding X, except when in X and Y
Any idea what's not working with the combining technique above, or how I can achieve this another (better) way? Thanks in advance!