I found this code on this site by AshFrame which I added to my functions PHP file and works perfectly to stop one category being displayed on my blog (I have a custom menu so have the category displayed separately)...

add_action('pre_get_posts', 'block_cat_query' );

function block_cat_query() {
    global $wp_query;   
    if( is_home() ) {
        $wp_query->query_vars['cat'] = '-98';

My question is how do I format this code to include a second category (in my case -92)? I tried duplicating the code but it generates a PHP error because you can only run the function once I think.

1 Answer 1


cat takes a comma deliminated list, so '-98,-92'

Further reading http://codex.wordpress.org/Class_Reference/WP_Query#Category_Parameters

  • Thank you Simon - that was straight forward (if you know what you are doing with Wordpress) ... ;-) ... really appreciate your help. Works great.
    – Paul
    Commented Sep 5, 2012 at 9:59
  • Pleasure. The codex is always my first port of call.. If I'm using a parameter I take the time to learn about the parameter fully so I can use it moot efficiently.. I only started doing this recently but found that its not actually that time consuming to have a little learning aside while working on a client project (obviously I don't bill them for that 30 seconds ha ha) Commented Sep 5, 2012 at 10:03

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.