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, for instance when they first land on your site.
This Views Global Filter module 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 a contextual filter to whatever views you like, even when these reside across multiple pages. This avoids you having to duplicate filters and the visitor having to re-select of filter values as the go from page to page on your site.
Configuration and Usage
A global filter is most commonly a field but can also be 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.
Configuration and usage details can be found in the README (D7) and README (D6) files.
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 the user profile, be it core or Profile2, 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 either the HTTP session, a cookie or on the Drupal database, they're easily picked up by other contributed modules. For example, regardless of the storage mechanism you selected on the configuration page, the following
global_filter_get_session_value('field_country_of_birth');
global_filter_get_session_value('view_users');
global_filter_get_session_value('keys');
global_filter_get_session_value('distance');
global_filter_get_session_value('view_autocycle');will return the current selection of the global filter for the field
field_country_of_birth, 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. A number of filter value selection widgets are available (drop-down, radio, text field etc.), defaulting to the field's native widget, as defined on the "Manage fields" tab of the content type. Core's rather plain widget for displaying hierarchical taxonomies is a bit boring. Why not pretty it up with Select with style, Autocomplete Deluxe or Hierarchical Select? If you decide to go with Hierarchical Select, please read the configuration tips in the README.
Q: Can I globally filter by date or date range using any of the standard date picker widgets?
A: Yes and you can use any of three Date types, i.e. plain, ISO or Unix Timestamp with their associated widgets (eg calendar popup). See the README.
Q: Can I globally filter by other ranges, like number ranges, alphabetical ranges, list ranges?
A: Yes in Global Filter 7.x-1.x-dev. Just enable the tiny Views plugin, Contextual Range Filter and she'll be right. You may enter "from" and "to" values via text fields or via this Slide with Style slider widget.
Q: Can I easily populate a global filter drop-down with countries?
A: Yes. On the block configuration page the filter driver selector has available the pseudo-field Location: Country. By default this produces a list of all countries in the world. However when the Location module is enabled the pseudo-field populates only the countries currently used in Locations on your system. To use Address field in the same way, see this forum comment.
Naturally you can also create your own list and optionally introduce a hierarchy, e.g. country->state->city by entering the countries of your choice as a taxonomy. This then gives you access to a number of attractive selection widgets, as mentioned in the first Q&A.
Q: Is there a way to globally filter content by proximity to a postal code the user enters into the filter box?
A: Sure is. The easiest way is via the Location module. See the README.
Q: If I don't use the Location module, can I still have my Views auto-filtered by the visitor's location, i.e. their city, while still allowing them to change the city filter?
A: Yes. See the README.
Q: Do my global filter selections remain when I log out, thus becoming an anonymous user?
A: Yes, if on the Session Cache API configuration page you select any option other than $_SESSION. See the article Erased memories and cracked Varnish for an explanation.
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 to their global defaults as configured on their block configuration pages.
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_period=sixties&keys=Beatles">Articles about the Beatles in the sixties</a>. This example assumes your site features a global filter for field_period (with an index "sixties"), as well as one for a search term.
Q: Can I use markers on a map to set my global filters and click through to a page that is globally filtered, e.g. by city?
A: Yes, see the previous question. Use a mapping module that allows you to have markers labeled with links or links in the balloons that pop up when markers are clicked, e.g IP Geolocation Views and Maps.
Q: Can I expose a View filter for a field that also acts as a global filter on that same View?
A: A global filter being active as a contextual filter on a field in a View does not prevent a normal filter also being exposed for that field in that View. Both apply. The View's exposed filter will apply after the global filter has been applied, further reducing the results of the View. This means you normally want "Allow multiple values" to be ticked at the bottom of the contextual filter panel. You cannot use Search Terms as both a global and a local filter on the same View.
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. In fact it may remain for some time after that, depending on the session storage mechanism and timeout selected on the Session Cache API configuration page.
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 style my pages differently depending on whether a global filter block is present?
A: Yes. The body tag will have CSS classes added to it for each global filter visible on the page:
<body class="gf fieldname1 fieldname1-value1">...Q: Can I globally filter by a mathematical expression I created as a pseudo-field in Views (Global: Math expression)?
A: Unfortunately not. This is because Views doesn't support contextual filters for expressions and Views Global Filter depends on contextual filters.
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
Development releases
Project Information
- Maintenance status: Actively maintained
- Development status: Under active development
- Reported installs: 562 sites currently report using this module. View usage statistics.
- Downloads: 5,311
- Last modified: May 21, 2013
