0

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)

0

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';
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.