categories – How do I get the category terms (multiple) queried on a category page?

Question

Here’s an example of a URL showing results from both the foo or bar category (note: I’m using pretty permalinks):

https://example.com/category/foo,bar

Based on this URL, and without parsing the URL itself, how can I get an array of the category terms used in this query?

I see them on the global $wp_query object here:

$wp_query->tax_query->queried_terms['category']['terms']

However, I’m looking for a more elegant way to retrieve them.

in progress 0
Jonny 6 months 2021-06-08T16:07:47-05:00 0 Answer 0 views 0

Answer ( 1 )

    0
    2021-08-06T07:06:37-05:00

    How about explode( ',', $wp_query->get( 'category_name' ) )

Leave an answer

Browse
Browse