0

I've had a fair amount of experience with WP, but this continues to make issues and could be on the brief for my next website. I'm looking for a "good" way to accomplish this task;

  • the post screen will have two custom taxonomies (tax-1 and tax-2)
  • each custom taxonomy will have several terms
  • the user can view posts by clicking on a link to a custom taxonomy archive, like www.domain.com/tax-1/term-1/

The catch is, the admin needs to be able to select two terms, one from each taxonomy. That posts needs to be found like this;

  • www.domain.com/tax-1/term-1/
  • www.domain.com/tax-2/term-2/
  • www.domain.com/not-sure-what-taxonomy/term-1-and-term-1

As far as I know, WP generates a category archive for each category/term/tag or whatever, so how do I combine two (or more) into one page? What would the URL look like, and would I need to $wp_rewrite magic for this?

I've found you can do this sort of thing: www.domain.com/category/tag-1,tag-2, which is great, but I'd rather have something like "tag-1-tag-2" as the URL structure.

I'm aware some people may say this isn't a "real" question. I'm looking for an idea, or some info from someone who has done this, not a load of code! I simply don't understand how this part of WP/querying is made up, and would love a little more knowledge. Surely someone else has also had this issue?

Many thanks for your time, Dan.

  • Look at tax_query arguments for WP_Query, the pre_get_posts and the parse_query filters and how to use callbacks on them. – kaiser May 21 '14 at 13:14
  • @kaiser - I do know a bit about these hooks, but I don't know how that would work in practice..? Perhaps a link with with terms passed in the URL. I could check the $_GET variable in URL to build a custom query I suppose. – Dan May 21 '14 at 17:49
1

Let's start with term archive concept and works backwards. It is easy for human to grasp it — it's an archive with posts having particular term.

On a more technical level though — it's a combination of query variables, which "tells" WordPress it is such archive. So if we dump query variables there will be variable designating the specific term posts should have.

And where do query variables come from? From the URL. Rewrite process turns URL (using rules configured) into query variables.

Now this process can actually be replicated from scratch (not by any means easily unfortunately). Needing specific kind of archive (or maybe even not quite archive) we can come up with query variables that produce it and rewrite rules for URLs that will result in those query variables.

It's relatively rarely done (it is convoluted part of WP core), so there aren't that many materials around. The closest I can think of for your description would probably be what Advanced Taxonomy Queries with Pretty URLs blog post describes.

  • Hi Rarst, thanks for taking the time to write. This has actually helped somewhat, and conformed my initial thoughts that this may be possible using URLs and the rewrite class. The article you've linked me to is great. I've read about two thirds, but I'd better go over it a few times! – Dan May 21 '14 at 18:00

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.