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 am excluding comments from specific categories. However, when I try to exclude more than one, it doesn't work.

This works: <?php if (!in_category('7')) comments_template(); ?>

This does not work:

<?php if (!in_category('7 , 9')) comments_template(); ?>


<?php if (!in_category('7')) comments_template(); ?>
<?php if (!in_category('9')) comments_template(); ?>
share|improve this question
up vote 2 down vote accepted

I would suggest using category slugs instead of ids. Please try something like this:

if ( ! in_category( array( 'bunnies', 'tacos', 'banana-pirates' ) ) ) {
share|improve this answer
lolbbq that is awesome! – Keith Groben May 23 '11 at 18:20

Put the IDs into an array, like this:

<?php if (!in_category(array(7, 9))) comments_template(); ?>

share|improve this answer

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.