Views Filters
Filters are what are used to reduce the result set of a View to a manageable amount of data. They are a critical part of the foundation of this system.
The filtering system is a compromise between flexibility and ease of use. To be truly powerful, filters should provide the ability to do an OR, but as it stands, these filters are all ANDed together. That means that every filter is applied. While the ability to do an OR would be nice, unfortunately the level of complexity in the interface to do that is well beyond the benefit that would be given.
The order of filters is irrelevant, though they can be re-ordered as a convenience.
- Field
- This is simply the field being filtered on.
- Operator
- The operator tells Views HOW to filter, and is part of the 'equation' of a filter. Usually this appears as a human readable sentence, and by simply reading the fieldname, with the operator and the value, it is clear what the operator means. For example, "Taxonomy Term", "Is One Of", "...some list of selected terms...".
- Value
- The Value field varies greatly based upon what field is being filtered, but is usually either a text box or a select box.
- Option
- The option field is specific to each field being filtered. The only currently existing option is on taxonomy terms, where the taxonomy depth is listed as an option. For taxonomy filters, you cannot specify "all" as a depth but must specify a number. The correct number to use depends on your site, but 2 will get roughly 90% of the uses. 3 will work for roughly 99% of the cases. The more you set the more expensive the query so set it to the smallest number that will work for your situation.
- Expose
- If a filter is 'exposed' the user will be presented with a widget to control the filter. When the expose button is clicked, the filter is added to the 'Exposed Filters' fieldset that appears just below the Filters.
Exposed Filters
Exposed filters are shown to the user, so that the result set can be modified. The typical example of this is to expose taxonomy as a filter so that the user can select which taxonomy term to filter on.
The order of the exposed filters controls the order in which they are presented to the user.
- Field
- This is the field being filtered; while all of the other fieldsets include an 'Add' button beneath it, this one does not; to add an exposed filter, go up to the Filters fieldset and click 'expose' on the filter you want exposed.
- Label
- This is the label presented to the user.
- Optional
- If a filter is set optional, an "" choice will be added (if it's a select). If a filter is not optional, a value must be provided to the view.
- Filter settings Default
- If a filter is set to optional, and this setting is checked, the actual settings of the filter will be the default; if this setting is not checked, the default will be set to blank or .
- Force Single
- If this setting is checked, any multi-select box available for this filter will be forced into a dropdown box and only one selection will be allowed. This is typical; dropdowns use less screen real estate and are easier for people to use.
- Lock Operator
- If this field is checked, the 'operator' will not be exposed, and the setting in the Filters section will be used. This setting is typical.
What follows is a list of filters that Views provides by default. Like other systems in Views, modules can provide more of these.
- Node: Has New Content
- Including this filter will reduce the node set to nodes that have been updated or have new content since the user last read the node, as well as unread nodes.
- Node: Published
- Filter by whether or not the node is published. This is recommended for most Views!
- Node: Front Page
- Filter by whether or not the node has been promoted to Front Page.
- Node: Sticky
- Filter by whether or not the node is set sticky.
- Node: Moderated
- Filter by whether or not the node is moderated.
- Node: Type
- Include or exclude nodes of the selected types.
- Node: Author is Anonymous
- This allows you to filter by whether or not the node author is anonymous.
- Node: Author is Current User
- This allows you to filter by whether or not the node was authored by the logged in user of the view.
- Node: Current User Authored or Commented
- This allows you to filter by whether or not the logged in user authored or commented on the node.
- Node: Distinct
- This filter ensures that each node may only be listed once, even if it matches multiple criteria. Use this if multiple taxonomy matches return duplicated nodes.
- Node: Author Name
- This allows you to filter by a particular user. You might not find this useful if you have a lot of users.
- Role: Author Role
- Include the node only if the author is a member of the selected role.
- Taxonomy: Term
- When filtering by taxonomy term you may specify the "depth" as an option. Please see the taxonomy help for more information.
- Taxonomy: Terms for a specific vocabulary
- Only terms associated with the specified will appear in the select box for this filter. When filtering by taxonomy term you may specify the 'depth' as an option. Please see the taxonomy help for more information.
- Taxonomy: Vocabulary Name
- This will filter a view to only nodes that contain a term in the associated vocabulary.

Filter Tip: Greater Then or Equal to
I misunderstood the logic of "Greater Then or Equal to" and thought a quick note might save others a little time.
The set-up: a simple view of basic job descriptions, with two fields in the filter section: salary-start, and salary-end, representing the salary range of the job ("This job pays between $30,000 and $40,000"). Both fields are integer fields created in CCK.
The goal: Allow users to search for jobs above a certain salary. For example, if I entered $32,000 in the search field, I'd expect to find all the jobs greater then or equal to $32,000.
What I did wrong: I exposed the salary start field and selected the operator "greater then or equal to". I realized after a few searches that not all of the appropriate records where turning up in my search. For example, I searched on $32,000, and yet a job that started at $30,000 was not showing up. Why was this not working? Wasn't $32,000 larger then $30,000?
The problem was my logic. When I exposed the salary-start field, I thought I was asking "Is my search term ($32,000) greater then or equal to the salary-start field of the job record?" Remember our sample record has a salary-start value of $30,000.
The revelation: What was really being asked is "Is the salary-start field ($30,000) greater then or equal to my search term ($32,000)?" The answer is, of course, no. So the record wouldn't show up in the found set.
The fix: Change my logic. I un-exposed the salary-start field, and instead exposed the salary-end field. Our sample record has a salary-end value of $40,000. Now the logic is "Is the salary-end field ($40,000) greater then or equal to my search value ($32,000). Since the answer is yes, the record is included in the found set.
Exposed Filters rely on Filters
I was confused by the interworkings of Filters and Exposed Filters. When you Expose a filter, it appears in both lists. The choices you make on the non-exposed version apply to the exposed version as well, as defaults in some cases, as parameters in others. If you delete the non-exposed version then you lose control of the Operator and Options fields, and possibly others. Hope this helps someone else in the future.
How to use patterns
The documentation should have some comments on how to use the patterns. I eventually (trial and error) figured out something that works, but there may be more that can be said.
Select "matches pattern" and then put a SQL pattern in the value field without the LIKE or quotes. For example to match any text field that begins with W the SQL pattern would be LIKE 'W%' but for the value field in views all you put in is W%.
Exposed Filters - Select List for an CCK Integer Field
* Rewrite of my previous post... it was too long and obscure *
Is it possible to create a drop down list box/select list exposed filter for a CCK Integer field.
I need an exposed filter on an integer field where users will only enter values between 1 and 10, and I want to show an exposed filter greater than filter using select list ie Show results where "my integer field" is > 2 for example.
Any help very appreciated.
rob | www.beetleweb.com
Force to only show enabled filter options
I am not sure about 5.x, but in 4.7 the exposed filter shows all the filter optiosn, regardless wether or not you set it to a subset of all options. This form_alter snippet changes that behaviout, to the IMO more appropriate subset of filter options.
---
Professional | Personal
Valid values for Operator?
The manual says:
But what is supposed to be "human readable"? Examples:
* I'm trying to filter a date field; I want to display all records matching "today" or seven days earlier. Operator "greater than or equal to" with Value "now" outputs dates in the future; but neither an expression like "now-7" or "seven days before now" works.
* I want to filter all records matching "current month, from the beginning". Of course, this value isn't acceped, also
So which values are valid for the operator?? There's for sure a reference for this, right???
Thanks, -asb
If you want to show only
If you want to show only nodes that are not older than 7 days, you have to add:
- Filter: "Node: Created Time"
- Operator: Is Greater Than (or Is Greater Than Or Equals)
- Value: now
- Option: -604800 (time is calculated in seconds - 604800 means: 7 days * 24 hours * 60 minutes * 60 seconds)
It works perfectly for me.
Please consider issue "Missing terms in filters"
(EDIT) About filters, a patch exists for the views.module v.5.x-1.6: See "Missing taxonomy terms in filters": http://drupal.org/node/199675
Using arguments to dynamically modify filters
I wanted a table view that gave me the previou n weeks of data, but setting variables in the argument handling code didn't seem to work at all, and the arguments didn't seem to be visible in other parts of the view.
After fussing for quite a while, I realized the trick was to forget about passing variables to the filters and to modify the filter directly in the argument handling code, instead. Thus, my final view had this argument handler:
$view->filter[1]['options'] = $args[1] * -604800;This modified the default filter, replacing the default value (-16 weeks, measured in seconds) with the URL argument multiplied by the number of seconds in one week.
Here's the whole form:
$view = new stdClass();$view->name = 'bikelogchart';
$view->description = 'Bike Log Chart';
$view->access = array (
0 => '1',
1 => '2',
);
$view->view_args_php = '';
$view->page = TRUE;
$view->page_title = 'Rolling Bike Log';
$view->page_header = '';
$view->page_header_format = '2';
$view->page_footer = '';
$view->page_footer_format = '2';
$view->page_empty = '';
$view->page_empty_format = '1';
$view->page_type = 'table';
$view->url = 'view/bikelogchart';
$view->use_pager = FALSE;
$view->nodes_per_page = '0';
$view->sort = array (
array (
'tablename' => 'node_data_field_ridedate',
'field' => 'field_ridedate_value',
'sortorder' => 'ASC',
'options' => '',
),
);
$view->argument = array (
array (
'type' => 'uid',
'argdefault' => '1',
'title' => '%1\'s Recent Bike Log',
'options' => '',
'wildcard' => '',
'wildcard_substitution' => '',
),
);
$view->field = array (
array (
'tablename' => 'node_data_field_ridedate',
'field' => 'field_ridedate_value',
'label' => 'Ride Date and Time',
'handler' => 'content_views_field_handler_ungroup',
'options' => 'short',
),
array (
'tablename' => 'node_data_field_ridedist',
'field' => 'field_ridedist_value',
'label' => 'Distance',
'handler' => 'content_views_field_handler_ungroup',
'options' => 'us_1',
),
array (
'tablename' => 'node_data_field_ridespeed',
'field' => 'field_ridespeed_value',
'label' => 'Average Speed',
'handler' => 'content_views_field_handler_ungroup',
'options' => 'us_1',
),
array (
'tablename' => 'node',
'field' => 'title',
'label' => 'Summary',
'handler' => 'views_handler_field_nodelink',
'options' => 'link',
),
);
$view->filter = array (
array (
'tablename' => 'node',
'field' => 'type',
'operator' => 'OR',
'options' => '',
'value' => array (
0 => 'bikelog',
),
),
array (
'tablename' => 'node_data_field_ridedate',
'field' => 'field_ridedate_value_default',
'operator' => '>=',
'options' => '-9676800',
'value' => 'now',
),
);
$view->exposed_filter = array (
);
$view->requires = array(node_data_field_ridedate, node_data_field_ridedist, node_data_field_ridespeed, node);
$views[$view->name] = $view;
Passing Filter values when embeding views
I spend some time searching for the answer on how to embed context-sensitive views with filters.
Filters need to be exposed.
Here is an example when searching for nodes that are created before currently displayed one
$view = views_get_view('next_nodes');$formated_date = format_date($node->created, 'custom', "Y-m-d H:i:s");
$filters = views_get_filter_values(array('op0' => '<', 'filter0' => $formated_date));
print views_build_view('block', $view, $arguments, false, 1, 0, 0, $filters);
The best way to get correct values for option and filter is to decode URL that u get when using exposed filters on your View Page
Do you think this could be an answer to my issue..?
Here's what i would like to do..do you think it could be done by what you're saying (i'm not a coding expert.. :( ) ?
http://drupal.org/node/365286
Great thanks for any thoughts!
Views filters: Taxonomy (contains, contains any words, contains
I need a way of doing a "full-text search query" of taxonomy terms of a particular vocabulary (1200 of them, so no drop down or autocomplete), alongside other exposed views filters built around the views & fast search module
With a "node title" filter you can have the filter: is equal to, contains, contains any words, contains all words, starts with, ends with, does not contain
I have noticed this is impossible with the taxonomy filters.
Is there a work around to this????
See also this thread
http://drupal.org/node/318179
Taxonomy term filtering without user selection
I am new to Drupal - I really like it!
I am building a view with a view type of node. I need to filter my nodes, which are classified according to a taxonomy. At view configuration time, I know the exact taxonomy term (I'll call it T for discussion purposes) that I wish to filter by. That I want to filter by T is static knowledge that I wish to build right into the view. The user's input is not required. I simply want to filter out nodes that are not classified as T. This does not appear to be possible, and seems it would be really neat if it were.
Meanwhile, I'm going to work around it by managing my own taxonomy-like CCK data.
Taxonomy term filtering without user selection - solved.
I am answering my own post here.
I figured out how to do what I wanted. Turns out I was wrong. By not Exposing my Taxonomy Term filter, it worked exactly the way I wanted, and no user interaction was required when the display was rendered.
Newbie mistake.
Problem with filters
Hi
I've cloned the glossary view and modified it to suit my needs. It works fine except when I reach the filter. If I do not have anything in the filter section, it displays everything how it should, except that it displays all the content I have. But I want to filter to only show a custom node that I've created, as soon as i check the following boxes:
- Is one of
- Custom node
all the results return blank, when I know I have 2 items that should be appearing in the list.
What am I doing wrong?
Created a view with exposed filters but they aren't showing up
I created a view with exposed filters. I can go to the page and see the filters just fine and use them. That part works. But I need to be able to embed the view in a panel. So I added a block to my view but it doesn't show the filters from the default display? Is there something else I need to do to make them show up or is this a limitation of views as a block in a panel. Technically speaking can I have /myproducts/myproduct?tid=1 in a panel and have the view us it and set the filter value like I can in the page example that works for me. Hope this makes sense.
Thanks for any help.
Exposed Filter for an Image Cache preset?
Is it somehow possible to expose an Image Cache preset using an exposed Views filter so that the user can have the option of selecting a preset?
Any pointers on this would be appreciated . Thanks
Bhambry