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 created a new category with the ID of 57, how do I exclude this category from the homepage/blog and then list the posts from this category on its own page?

this is what my index.php looks like

            $popular_count = 1;
            query_posts( array( 'orderby' => 'comment_count','posts_per_page' => 6 ) );
            if ( have_posts() ) : while ( have_posts() ) : the_post();

so how to add that bit of code is a little confusing

share|improve this question

Rather than performing a separate query, to exclude a category (or any other taxonomy) term, you can hook into pre_get_posts:

add_action('pre_get_posts', 'wpse41820_exclude_cat_from_front_page');
function wpse41820_exclude_cat_from_front_page( $query ){
    if( $query->is_main_query() && is_front_page() ){
        $tax_query = array(array(
            'taxonomy' => 'category',
            'field' => 'id',
            'terms' => array( 57 ),
            'operator' => 'NOT IN'

    return $query;

To exclude a slug, alter the $tax_query accordingly:

        $tax_query = array(array(
            'taxonomy' => 'category',
            'field' => 'slug',
            'terms' => array( 'term-slug' ),
            'operator' => 'NOT IN'
share|improve this answer

Use a custom query for both.

   <?php if (have_posts()) : 

        $args = array(
                          'orderby' => 'comment_count',
                      'posts_per_page' => 6,
                      'cat' => -57,

        $my_query = new WP_Query($args);

        while ($my_query->have_posts()) : $my_query->the_post(); ?>

The negative sign in front of the category denotes an exclusion.

I made the edit to work with the code you provided.

share|improve this answer
where do i place this? – Joe Feb 9 '12 at 21:47
@Joe In your index.php, replacing the code you posted. – Kyle Feb 9 '12 at 22:17
i tried that and it didnt exclude the category which is y im a little confused – Joe Feb 9 '12 at 22:20
is there anything that could be affecting this from working? I put I replaced it correctly and its not working for some reason.. – Joe Feb 9 '12 at 22:26
@Joe I edited my answer again to use what I know works. Try replacing your code with my edit and see if it works. – Kyle Feb 9 '12 at 23:03

protected by toscho Jun 11 '12 at 11:50

Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).

Would you like to answer one of these unanswered questions instead?

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