Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I have a page of multiple categories (mysite.com/?cat=1,2,3,4). My archive template shows the name of the selected category as a heading. Now I have four categories, but only the name of the first shows up. Instead, I'd like to check if more than one category is selected and then show no heading.

So, how do I find out how many categories are selected? (-> This needs to work outside the Loop)

share|improve this question

1 Answer 1

up vote 0 down vote accepted

This is untested, but I think it should work. Multiple categories will result in the category__in query var containing an array of the queried categories-

if( isset( $wp_query->query_vars['category__in'] )
&& count( $wp_query->query_vars['category__in'] ) > 1 ){
    echo 'multiple categories queried';
}
share|improve this answer
    
Perfect! Thank you :D –  eevaa Aug 23 '13 at 18:30

Your Answer

 
discard

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.