2

This question assumes that you know about the various complex taxonomy queries available from the WP_Query API. I know about tax_query as well as about things like category__and, which allow you to run multi-term queries inside a template.

It also takes for granted the knowledge that you can manually create links, both pretty (/category/mac+mobile/) and ugly (/?cat=2+3) that will generate the results similar to many of the tax_query (or at least category__and) options.

The question is: What is the best way to generate such links within code, so that a theme can automatically link to screens showing complex mixes of categories.

  • The solution should be forward compatible and use standard WP if possible.
  • It should ideally work with any possible permalinks and category-permalink configuration.
  • Ideally it would work with any order of categories, as well as with categories nested inside a hierarchical taxonomy.
  • It should accomodate both intersections (a+b only posts in both categories are returned) and unions (a,b any post in one or the other category works).

As far as I can tell there is no built-in function that can achieve this. The similar function is get_term_link() but it only accepts a single term. Ideally core would have something like get_tax_query_link() that accepted a tax_query and rendered a link that would show the desired results.

  • Ideally core would have... - this sounds like a trac ticket, not a question. :) What kind of answer are you looking for here precisely? – Rarst May 12 '13 at 14:24