0

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

1 Answer 1

2

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() !?

2
  • 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, 2011 at 1:52
  • That's exactly the solution offered by One Trick Pony...
    – brasofilo
    Jun 22, 2012 at 20:12

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.