Use Views Global Filter on sites that feature multiple Views. 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.
Views Global Filter implements the picked once, operates site-wide (POOS) principle. This means you can place anywhere on your site a selection widget (drop-down, check boxes etc) to globally filter all or some of your views. When the user picks a value from the global selector, 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 avoids the visitor having to re-select their choice as they go from page to page.
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.
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.
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.
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 .
Q: Can I globally filter by taxonomy term or tag?
A: Absolutely! Just wrap up the vocabulary in a field (recommended) or create a view for it (if you want to do it the hard way). 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 field 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. Note: for date properties (e.g. created date, modified date on nodes), as opposed to date fields, see the next question.
Q: Can I globally filter by other ranges, like number ranges, alphabetical ranges, list ranges or date ranges?
A: Yes. To filter by ranges enable Views Contextual Range Filter. You may enter "from" and "to" values via text fields or via the Slide with Style slider widget. Note that you don't need Views Global Filter or Views Contextual Range Filter if all you're after is a slider to enter from and to values via an exposed filter on a single View. Slide with Style does that out of the box by itself.
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 Country name. 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 reference point?
A: Sure is. For instance when you use the Location module you can have the visitor enter a postcode and a distance. Or if using Geofield 7.x-2.x-dev, the global proximity filter returns locations within a radius of the visitor's position (HTML5) by default and within a radius of a city or address, if entered. See the README.
Q: If I don't use the Location or Geofield modules, 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=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 by the country or city the marker is in?
A: Yes, see the previous question. Use a mapping module that allows you to put links in the marker popup balloons, 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 regular filter also being exposed for that field in that View. Both apply. Always. This can lead to counter-intuitive results, but enable View Filter Harmonizer and you'll be fine.
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.