Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

So it's quite obvious to how exclude certain categories from within a template, but I don't want to have to modify 4 templates so that they ignore a certain category.

Is there a way that I can exclude a category from showing up within the "blog" set within the Reading settings? I'm assigning the blog to a Page named "Blog" ... but obviously archives and searches are going to need to be blind to this one exceeded category too.

I'd just do much rather do it within functions.php

share|improve this question
add comment

1 Answer 1

up vote 1 down vote accepted

http://codex.wordpress.org/Function_Reference/is_main_query

add_action( 'pre_get_posts', 'foo_modify_query_exclude_category' );
function foo_modify_query_exclude_category( $query ) {
    if ( $query->is_main_query() && ! $query->get( 'cat' ) )
        $query->set( 'cat', '-5' );
}

So it's quite obvious to how exclude certain categories from within a template, ...

Actually it's not. Are you talking about query_posts() !?

share|improve this answer
    
WP_Query or query_posts ... it's easy to exclude a category form the Template level. But I want to do it from within Functions. –  dcolumbus Dec 23 '11 at 1:52
    
That's exactly the solution offered by One Trick Pony... –  brasofilo Jun 22 '12 at 20:12
add comment

Your Answer

 
discard

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.