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 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.

share|improve this question
up vote 1 down vote accepted

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

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

share|improve this answer
Thank you Simon - that was straight forward (if you know what you are doing with Wordpress) ... ;-) ... really appreciate your help. Works great. – Paul Sep 5 '12 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) – Simon Forster Sep 5 '12 at 10:03

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.