Skip to main content
2 of 2
replaced http://wordpress.stackexchange.com/ with https://wordpress.stackexchange.com/

I would use get_queried_object() (see this post) rather than $wp_query->query_vars

Also you should use $term->slug (and $category->slug) instead of $term->name.

Apart from that, your method is as good as any.

Stephen Harris
  • 32.6k
  • 6
  • 84
  • 118