Stack Exchange network consists of 183 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.
Ask questions, find answers and collaborate at work with Stack Overflow for Teams.
Ask questions, find answers and collaborate at work with Stack Overflow for Teams. Explore Teams
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
I would use get_queried_object() (see this postsee this post) rather than $wp_query->query_vars
get_queried_object()
$wp_query->query_vars
Also you should use $term->slug (and $category->slug) instead of $term->name.
$term->slug
$category->slug
$term->name
Apart from that, your method is as good as any.
I would use get_queried_object() (see this post) rather than $wp_query->query_vars