I am trying to select posts that have category id 4
but exclude posts that also have category id 2
Here's what i'm trying
$query = new WP_Query(array(
"cat__in" => array(4),
"cat__not_in" => array(2),
"post_type" => "post",
"post_status" => "publish",
"orderby" => "date",
"order" => "DESC",
"posts_per_page" => $limit,
"offset" => 0
));
However, it's not making the proper selection. What am I doing wrong?
cat__in
andcat__not_in
is not valid parameters. Go and check the valid category parameters inWP_Query
. You can just simply pass'cat'=>4
to your arguments to just get posts from category 4. Or as Brad suggested, usepre_get_posts
and pass the same parameters to that