I need to select all posts from database without fetching some categories.
For example I fetch posts with this code:

$featuredPosts = new WP_Query();

So, now, how can i remove categories with id of: 22, 23 and 24?

1 Answer 1


Make query like this:

$query = new WP_Query( array( 'posts_per_page' => -1, 'category__not_in' => array( 2, 6 ) ) );

2, 6 being the category ID you want to exclude.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.