INTRODUCTION
TL;DR: This module allows contextual filter arguments and exposed filters to be used as replacement tokens in other filters or table arguments.
What this means:
- You can use Contextual Filters (even Null ones) to accept arbitrary input, and use that input as values in one or more Filters (example: searching for node titles containing some search keyword).
- You can reuse an exposed Filter value as a value in other Filters (example: users can search for nodes based on title or tag using one field by exposing a node's "Title" field and using input in that field in an OR non-exposed filter on taxonomy terms).
Enhanced Contextual Filters
Contextual Filters allow a View to be filtered based on arguments passed via URL or other embedded method (e.g. the View Reference module), but contextual filters are inflexible compared with normal filters (contextual filters do not allow for "contains," "begins with," "ends with," etc.). With this module, you can use contextual filter values in filters.
Enhanced Filters
Exposing filters to allow users to search your site can be very powerful. Unfortunately, traditionally you need to expose a filter for every field that a user may want to search. With this module, you can expose a single filter, and reuse that input in many other (non-exposed) filters.
EXAMPLES
To search for a node by title containing some keywords:
- Create a new node-based ("Content") View: Go to admin/structure/views/add and under "Show", choose "Content".
- Add a "Global: Null" Contextual Filter (this step is required to allow the view to receive at least 1 argument).
- Add a "Content: Title" Filter: Under "Filter Criteria," click "Add." Choose "Content: Title," set the "Operator" to "Contains", and set the "Value" to "***!1***" (without the quotes). Click "Apply."
- Done! Any value passed as the first Contextual Filter argument will be used as the value for the Content: Title filter.
To search for nodes containing the same title as a specified node:
- Start by completing the example "to search for a node by title containing some keywords," as given above.
- Edit the "Global: Null" Contextual Filter: Enable "Specify validation criteria," and set "Validator" to "Content."
- Edit the "Content: Title (contains ***!1***)" filter: Change the "Value" from "***!1***" to "***%1***".
- Done! If you pass in a valid NID as the first Contextual Filter argument, its title will be used as the search value for the Content: Title filter.
Search node title, tag, author etc. with a single exposed search field
- Create a new node-based ("Content") View: Go to admin/structure/views/add and under "Show", choose "Content".
- Add "Content: Author" Relationship
- Add a "Content: Title" Filter: Under "Filter Criteria," click "Add." Choose "Content: Title," set the "Operator" to "Contains", and expose the filter. Click "Apply."
- Add "User: Name (raw)" filter, do not expose the filter, set Operator to "Contains" and Value to "***!title***".
- Done! Anything entered in the "Title" field will also search the username. You may want to change the "Title" label to "Search", and add taxonomy terms (also reusing the "***!title***" input), the options are limitless!
INSTALLATION
Activate the module, then administer a desired View. Add as many Contextual Filters as you need filter values (using "Global: Null", if appropriate), then insert corresponding tokens ("***!1***" for the first value, "***!2***" for the second, etc.) as filter values. Additionally, "***%1***" may be used to insert the title for the first argument (for example, if the argument is a node), and so on.
KNOWN ISSUES/SHORTCOMINGS
- The Search API module does not support any query substitutions (#2898924: Views query substitutions don't get substituted), so Search API integration is unsupported/unfeasible.
- The underlying
hook_views_query_substitutions()
only supports returning string values, so it is impossible to break an incoming string into a list. This means that filters using "Contains any word" or "Contains all words" will only "see" one word, even if it is separated by spaces. For "Contains any word," use a Regular Expression filter instead coupled with the REGEX replacement pattern.
Depends on
Dependencies of the latest stable release
No dependencies recorded for this project.
Required by
Tracked projects that depend on this one
No tracked projects depend on this one yet.
More in the Views ecosystem
Most installed first