Download & Extend

Views Global Filter

A lot goes on in global filtering...

Use Views Global Filter on sites that feature multiple Views (or other page elements, like forms, see the Other uses section). You want the views to be driven by the same filter selection, for instance a country, a date range, a search term or even proximity to a post code. These views may be on the same page or scattered across several pages on your site, however you want to offer the visitor the convenience of setting the filter for all these views only once, e.g. when they first arrive at the front page.
This Views Global Filter plugin allows you to place anywhere on your site as a small block, a drop-down, multi-select or text box to globally filter all or some of your views by the selected value(s). When the user selects a value from this global selector, which could be a country, customer name, price range etc, the value is invisibly passed as an argument (aka Contextual Filter in D7) to whatever views you like, even when these reside across multiple pages. This avoids having to resort to duplication of filters and re-selection of filter values as the visitor goes from page to page on your site.

Configuration and Usage

A global filter can be either a field or a View (that's right: the output of view pushed into a selector for the default of another view).
The 7.x version supports both fields and Views (7.x-3.x) and comes with various filter selection widgets. The 6.x version is less feature-rich. It supports Views (6.x-3.x only) and as far as fields go, only the common node properties (e.g. type, year/month created etc.), not CCK fields, yet.

Configuration and usage details can be found in the README (D7) and README (D6) files.

In D6, the initial selection for each global filter will be "all". In D7 the administrator can set a global default for the field or view selected to drive the filter. This default will be active until the user makes a different filter selection. If the global filter is a field that also appears on user profiles, then authenticated users can override the global filter default with their personal choice, taken automatically from their profile upon login.

Further options

A special auto-cycle filter is available under the "Advanced configuration" fieldset on the Configuration >> Global Filter page. You can use this to create rotating block content, such as ads, news flashes or user profile pictures, that have to follow a specific logical sequence, for instance chronological (by creation or modification date), alphabetical or by vocabulary term order. All details are in the README (D7) and README (D6) files.
Or for a very different use of Global Filter's auto-cycle filter, check this out: http://bitly.com/ss8CDI .

Other uses

While originally designed to be used in combination with the Views module, Global Filters may also be used to input global selections to other page elements, like forms and blocks. As the current global filter selections are stored in the user's $_SESSION, they're easily picked up by other contributed modules. For example:

  $_SESSION['global_filter']['field_country']
  $_SESSION['global_fitler']['view_users']
  $_SESSION['global_filter']['keys']
  $_SESSION['global_filter']['distance']
  $_SESSION['global_fitler']['view_autocycle']

will return the current selection of the global field filter field_country, the global view filter users, the search term box, the location proximity and the current value of the auto-cycle filter, respectively. These values may thus be passed to code that creates some form, a block etc.

FAQ's

Q: Can I globally filter by taxonomy term or tag?
A: Absolutely! Just wrap up the vocabulary in a field or create a view for it. Then select that field or view from the drop-down when you configure the global filter block.

Q: I don't like core's plain way of displaying hierarchical taxonomies much. Can I pretty it up?
A: Try Select with style. It works well with Global Filter.

Q: Can I globally filter by date or date range using any of the standard date picker widgets?
A: Yes and here is how. If your content does not already have a date field attached, add one as per normal via the Manage fields tab on the content type page. You may pick any of three Date types, i.e. plain, ISO or Unix Timestamp. Just be aware of this bug in the Date module: #1477180: Start date not inclusive for Dates based Unix Timestamp. So until this is fixed, maybe avoid Unix Timestamp. When prompted pick any of the available date selection widgets, e.g popup calendar or the triple select list. You may tick the "Collect an End date" box too, if you wish. After you have configured a global filter block for the field date or field date range, the global filter will render itself using the same widget as you've picked for the field. However, the global filter will always appear as a date range. Filtering by a single date would be a little restrictive! Finally, as with any other global filter you need to hook it into your view as a contextual filter. Use either just the field start date or create a second contextual filter to also require the content's end date being inside the filter range. Important: In either case make sure you scroll down the bottom of the contextual filter panel to the heading "Dates to compare". Press the button This field only.

Q: Is there a way to globally filter content by proximity to a post code the user enters into the filter box?
Sure is. Install the Location module. Then configure a Global Filter block to be driven by the "Location: Distance/Proximity" pseudo-field and hook it into your locations/views View as a contextual filter. Global Filter's contextual filter plug-in will allow you to set the proximity cut-off distance, that is to include only content within a range of, say, 50 km of the post code entered by the user.

Q: If the widget I chose for my field is an autocomplete field, will Global Filter use the same widget?
A: Yes, in general Global Filter honours any field widget you decide to inherit on the Global Filter block configuration page. Autocomplete Deluxe is an example of a widget known to work fine with Global Filter.

Q: Is there an easy way to reset all global filters and/or reset a specific global filter?
A: Yes. Append ?clear-global-filters or ?clear-global-filters=filter_name1,filter_name2 to the URL in the browser address bar. You can also create links on your site to do this e.g. <a href="/?clear-global-filters">Clear filters</a> embedded anywhere on your site will take the visitor to the home page while also clearing all global filters.

Q: Can I create links on my site, in an email or on another site, pointing to pages on my site AND setting one or more global filters at the same time?
A: Yes and here's an example: <a href="http://mysite.com.au/music?field_country=23,25&keys=Beatles">Articles about the Beatles in Australia and NZ</a>. This example assumes your site features a taxonomy-driven global filter for country (with 23 and 25 being the taxonomy term id's for Australia and NZ), as well as a search terms global filter.

Q: How do I temporarily disable a global filter?
A: Place its block in the -None- region. Note that your last filter value will remain active until you log out, or if not logged in, until you close your browser.

Q: How do I delete a global filter?
A: At Structure >> Blocks click configure. Then deselect the selected filter name by picking the very first option (-None-). Press Save block. This will auto-delete the filter from all views using it as their default contextual filter.

Q: Can I globally filter by image?
A: Yes, although I don't see much use for it. The global filter field_image will appear as a text box. Depending on the field you select as the Contextual Filter for your view you enter either the title of the image (Content: Image (field_image:title)) or a plus-sign separated sequence of file identifiers, e.g. 3+23+9 (select Content: Image (field_image:fid)). The latter requires Allow multiple values to be ticked in the More field-set at the bottom of the Contextual Filter configuration panel.

Development sponsored by flink, the Drupal experts collective.

Downloads

Recommended releases

Version Downloads Date Links
7.x-1.4 tar.gz (26.93 KB) | zip (33.9 KB) 2012-Apr-15 Notes
6.x-1.0 tar.gz (17.73 KB) | zip (21.9 KB) 2012-Feb-19 Notes

Development releases

Version Downloads Date Links
7.x-1.x-dev tar.gz (26.94 KB) | zip (33.91 KB) 2012-May-25 Notes
6.x-1.x-dev tar.gz (17.74 KB) | zip (21.91 KB) 2012-Feb-06 Notes

Project Information


Maintainers for Views Global Filter

  • RdeBoer - 101 commits
    last: 15 hours ago, first: 26 weeks ago

Issues for Views Global Filter

To avoid duplicates, please search before submitting a new issue.
All issues
Bug reports
nobody click here