4

What I have are custom posts (of a custom post type, wps_business) that have two taxonomies (wps_location & wps_type), and I would like to list all the terms from type of a specific location.

For example:

  • POST 1: King's English Cafe, location: London, type: Restaurant (parent), English
  • POST 2: La Madeline, location: Paris, type Restaurant (parent), French
  • POST 3: Uncle Julios, location: London, type: Restaurant (parent), Mexican
  • POST 4: San Marinos, location: London, type: Restaurant (parent), Italian
  • POST 5: Chipotle, location: London, type: Restaurant (parent), Mexican
  • POST 6: Olive Garden, location: London, type: Restaurant (parent), Italian
  • POST 7: Home Depot, location: London, type: Home & Garden (parent), [no-child]
  • POST 8: Lowe's, location: London, type: Home & Garden (parent), [no-child]
  • POST 9: Frank's Car, location: London, type: Local (parent), Mechanic
  • POST 10: Smith's Car, location: London, type: Local (parent), Mechanic
  • POST 11: King's Bank, location: London, type: Local (parent), Bank

..etc..

So what I would like to is have a display on the location London page is just a list of terms from type that have posts associated with location London (taxonomy: location). So...

Home & Garden (2)

Local (3)

  • Mechanic (2)
  • Bank (1)

Restaurant (5)

  • English (1)
  • Mexican (2)
  • Italian (2)

I was thinking that I needed to customize Walker_Category class; however, I believe that a more complex query may be needed. I'd rather not fetch all posts and cycle through to create this. Suggestions? Is there a SQL that will fetch these?

4

I've done something like this in the Query Multiple Taxonomies plugin:

https://github.com/scribu/wp-query-multiple-taxonomies/blob/master/core.php

The good news is that it's a generic solution: it works for any combination of posts and taxonomies.

The bad news is that it might take some effort to figure out how it's done.

  • 2
    I've used it for exactly this scenario and works really well. – MZAweb Jun 8 '12 at 1:35

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.