I am filtering posts by two categories, using the following style of query:


which gives a list of all posts that are in the animals category and in the blue category.

I want the resulting page to display the names of the two categories, as in "Animals and Blue", as a header over the list of excerpted posts.

My theme has an option to display the category title, which it pulls from single_cat_title(). But for two-category searches, this gives only the first of the two categories, as in "Animals."

I'm trying to figure out a way to modify my theme to display also the second category, when there is one. But I can't figure out where Wordpress keeps the information.

Does Wordpress save the title of the 2nd category anywhere? Is there a way to dig it out from somewhere? Can anybody help? Many thanks in advance.


Okay, I managed to track down the answer, with help from the "Debug This" plugin and investigating the coding of the "Beautiful Taxonomy Filters" plugin.

So far as I can find, Wordpress saves full details (including Title, ID and Slug) of only the first taxonomy and first term queried.

For any additional terms or taxonomies queried, Wordpress saves only the slug.

This info is located within the gob of information in $wp_query, which can be pulled out like so:

$queried_taxonomies = $wp_query->tax_query->queries;

The slugs of all queried taxonomies will be found in:


Where X is the number of the taxonomy, starting from 0.

The slugs of all queried terms are in:


Where X is as above and Y is the number of the term queried for that taxonomy, starting at 0.

So for example if the query was of two terms of one taxonomy, the slug of the second term will be in:


And if you queried one term each of two taxonomies, the slugs of the second taxonomy and term will be in:


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.