NOTE: The links will work If you copy & paste them. (I’m a newbie so I am not allowed to add to many links to the question)
I have a few taxonomies that I would like to query a range from, for example
- price
- age
- vintage
I found this question which helped me some
How to pass URL parameters for advanced taxonomy queries with multiple terms for one custom taxonomy
With the above examples I could query the age taxonomy as an example for the year of 10 and 20
- tax.jenswedin.com/age/10,20/
- tax.jenswedin.com/?age=10,20
This works ok.
But if I would like to do an query for an an range of ages, for example form 10-20 I would need to
- tax.jenswedin.com/age/10,11,12,13,14,15,16,17,18,19,20/
And if I would like to do a range between 10-100 you can imagine it will will not look that good.
So I tried to put the age terms in sub taxonomy terms so the structure would be like this
- 11-20
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 21-30
- …
- …
By doing this I could now query like this
- tax.jenswedin.com/age/11-20/
And it would work, it would show all ages within 11-20
But this way is quite inflexible, I would need just range between 15-20 this wouldn’t work.
What I would like to know if there is a way that the range is dynamic and more flexible. I know that @scribu had a plugin (which isn’t supported longer) that had the had support for ranges with the min & max for custom fields. But I haven’t seen anything like this for taxonomies.
- chwisgi.com/?age-min=20&age-max=30
Any help would be appreciated.
You could take the query var and programatically expand the numbers between your minimum value and maximum value.
Assuming http://tax.jenswedin.com/age/10,20/ is rewritten to http://tax.jenswedin.com/?age=10,20, then (pseudo code)
This works well for things like numbers. But you could do a
foreach
loop over the $range array and make the values whatever you need them be.