Range Rover in mountain Range
Contextual Range Filter settings page
Price range slider

Views Contextual Range Filter is a plugin for Views that adds the option to contextually filter not just by a single value, but also by range, such as a price range.

Please be aware that contextual filters are different from exposed filters. This module is about contextual filters only.

Just like normal contextual filter arguments, contextual range filter arguments may be set by appending them to the URL. Use the double hyphen '--' as the from/to separator:
http://yoursite.com/somepath/75--99.95

Numeric and alphabetical ranges are supported as well as date ranges. Node ids, user ids and even taxonomy term ids are all special cases of numbers so will work also.

For filtering on date ranges use either absolute dates:

http://yoursite.com/someotherpath/2020-06-30--2020-12-31 (D8/9)

or use the relative format, which supports natural language phrases like two weeks ago and first Tuesday of November, but also alternative notations for absolute dates:
http://yoursite.com/someotherpath/6 months ago--30Nov (D7/8/9).

Note: to enable the relative format, you need to tick the associated checkbox on the Views contextual filter form.

For multiple ranges (be they numeric, alphabetic or date ranges), you may use the OR operator (i.e. +).
You can also negate the range(s) by ticking the "Exclude" box on the Views Contextual filter configuration panel, in the "More" section.

To convert a contextual filter to a range filter, first create in the Views UI a plain contextual filter, as per normal. Then visit the Contextual Range Filter configuration page .../admin/config/content/contextual-range-filter (2nd picture, click to enlarge), find your contextual filter name and tick the box next to it to turn it into a contextual range filter.
The README contains a number of examples of how to use contextual range filter arguments for numbers, strings and lists.

D8 Extra's

This module re-introduces the Default Contextual PHP Code filter that was dropped from the Views module in D8. Using short PHP code snippets it's easy to create sidebar blocks of Related content that go beyond simple taxonomies. For instance you can make a block showing nearby locations. Or related products that are cheaper or up to 20% more expensive than the main product shown. Or other blog posts published within +/- 7 days of the one you're currently viewing.
See Related Content examples,

D7 Extra's

If you wish to offer your visitors a UI to enter "from" and "to" contextual filter values in textfields, install the Views Global Filter module (D7 only).
For a range slider (bottom picture), also enable together with Views Global Filter the Slide with Style module (D7) from the Select with Style package. Note: Slide with Style can also be used as a widget for Views' exposed filters. You don't need Views Global Filter for that.

Which version of PHP?

D9
Use PHP version 7.3 or later.
D8
Use PHP version 7.2 or later.
D7
If you run PHP version 5.3.9 or later use the latest version of this module. Otherwise go for 7.x-1.1.

Try it yourself, live online

Want a quick demo? Follow these steps to create a test site in seconds on simplytest.me.

  • For D7 click here. For D8 click here.
  • Press "Launch sandbox". Next, press Login to enter your simplytest.me site (admin/admin).
  • Enable the Views UI and Devel Generate modules.
  • At Structure >> Views enable the View Glossary.
  • On the Configuration page, admin/config, under "Development", click Generate content to generate 50 or so random pages.
  • Then back on the Configuration page click Contextual Range Filter. On the next page tick the box in front of Title in view Glossary. Save.
  • Visit the Glossary View by typing its URI in the browser address bar, appending a contextual filter range, e.g. /glossary/d--r.

Nice?

FAQs

Q: What about ranges on D7 date fields? By this I mean fields supplied via the Date module (D7), as opposed to core's created and updated date properties?
A: The combo of D7 Views together with the D7 Date module already supports contextual date filter ranges for fields, via its submodule Date Views. So you don't need this module in D7 when you're after date ranges for fields and are happy to enter absolute dates. However, if you wish to use relative dates in your ranges, using natural phrases like 3 months ago, then you do need this module. No need to enable Date Views in that case.

Supporting organizations: 
all code and documentation

Project information

Releases