Proper syntax to add boolean in array()

Your code fails because:

array(
    'cat' => -9, -4
);

is the same as:

array(
    'cat' => -9,
    -4
);

The -4 is its own element, not a part of the ‘cat’ argument.

The correct way to do what you tried to do would be:

array ( 
    'cat' => array( -9, -4 )
);

But this too would have failed because ‘cat’ takes a single value, not a collection/array/list of them, and it’s not the correct parameter to pass:

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

  • cat (int) – use category id.
  • category_name (string) – use category slug (NOT name).
  • category__and (array) – use category id.
  • category__in (array) – use category id.
  • category__not_in (array) – use category id.

So what you actually wanted was category__in.

I also recommend you read up on basic arrays in PHP on php.net, especially the use of $array[] = -4; and the [] operator.

But More Worryingly

You’re going about this the wrong way. First thing to learn is that any code that uses query_posts is almost by definition bad code.

The reason for this is that what you’re doing is horrendously inefficient, it means WordPress has already done all the database lifting, and you then say “No, go back and do it all over again but with these parameters instead”.

If WordPress were an office assistant, it would turn around and ask why you didn’t just tell it what you wanted to begin with, well you can!

See this question on why and when you should/shouldn’t use query_posts

pre_get_posts

For example, this modifies the homepage query to filter out categories:

function filter_cats_on_home( $query ) {
    if ( $query->is_home() && $query->is_main_query() ) {
        $query->set( 'category__in', array( -1,-1347) );
    }
}
add_filter( 'pre_get_posts', 'filter_cats_on_home' );

This is much, much, much cleaner and faster than having a query_posts on the homepage.

But Even More Worryingly

'cat' => -9,

I see hardcoded values. This isn’t portable. Instead do the following:

  • Store a term/category ID in an option or post meta and provide a user interface of some kind
  • Reference the categories by post slug so that an export and import of the content or a site move doesn’t break everything.

error code: 523