WP_Query Not Working with Variable

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. 🙂

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)