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


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.