In your wp_query
, you should use NOT IN
which I don’t see. In your arguments for WP_Query()
, you should use category__not_in
instead of cat
. So, change your code to:
Excluding Single Category
$args = array(
'post_type' => 'post',
'posts_per_page' => 15,
'paged' => $paged,
'category__not_in' => 'X', // string
);
If you wish to exclude multiple categories then assign the category ID’s comma separated in an array, not as a string. Check the below code
Excluding Multiple Categories and Displaying Posts That are from X and Y
$args = array(
'post_type' => 'post',
'posts_per_page' => 15,
'paged' => $paged,
'category__in' => array(X,Y), // Array
'post__not_in' => array(X),
);
Below is the full Query:
$args = array(
'post_type' => 'post',
'posts_per_page' => 15,
'paged' => $paged,
'category__in' => array(X,Y), // Array
'post__not_in' => array(X),
);
$your_query = new WP_Query( $args );
while( $your_query->have_posts() ):
$your_query->the_post();
the_title();
endwhile;
wp_reset_postdata();
Note: Use ID not the category slug or name