-1

I'm new two wordpress so sorry in advance if this question might be very basic. Depending on which category a post is, I do some script things and I ask inside the loop in this way:

<?php if (has_category('category_1')):?>
   // do some stuff
<? endif; ?>

this works pretty fine. But how can I ask for if post has two specific categories like:

<?php if (has_category('category_1') && has_category('category_2'):?>
  // do some stuff
<? endif; ?>

this does not seem to work. What am I doing wrong?

1
  • can you write it as an answer with comments. sorry as I stated I am very average.
    – user49869
    Apr 7, 2014 at 18:59

1 Answer 1

2

You can specify multiple categories within has_category like so:

if ( has_category( array( 'category_1', 'category_2' ) ) {
    // do something
}

However, I am not sure if this acts as AND or OR, meaning does it require that ALL categories specified are matched, or one of the X supplied (category_1 OR category_2).

In any case, your syntax should work perfectly fine. double check on the spelling perhaps?

1
  • it is working, thank you for the spelling tip! was that fault.
    – user49869
    Apr 7, 2014 at 19:04

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.