I’m pretty sure it’s because you’ve got mixed nested quotes when you’re setting $CatIDsCode
.
So this should fix it:
$camp_posts_bynumber = new WP_Query (array ('cat' => $CatIDs));
P.S. Move $CatIDs= implode(',', $out);
outside of the foreach
loop. 🙂