WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have made a custom category "card_categories". I want to exclude some posts from that category on the category page. For eg :- category id 51 has posts with id's 1,2,3,4,5,6,7,8,9 Now I want that on the category page it should show posts only with post id 4,5,6,7,8,9

So, Is it possible that i can exclude posts from a category.

share|improve this question

If you want to exclude posts from a particular category then you could try putting this in your functions.php

function exclude_posts_from_category( $query ) {
    $catname = "Put you category name here";
    if ( $query->is_category() && ( $catname == $query->query_vars['category_name'] ) ) {
        $query->query_vars['post__not_in '] = array( 1, 2, 3 );
add_action( 'pre_get_posts', 'exclude_posts_from_category' );

You can use $query->query_vars['post__in '] = array( 1, 2, 3 ); in case you want to specify the posts that should be included ( It will only include the post id you mention and if they are in the current category ).

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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