Views exposed filters

An exposed filter is a Views filter shown to visitors as a form control, so they can narrow a list themselves by title, category, author or another field.

Learn DrupalDrupal glossary

An exposed filter is a Views filter that is shown to the visitor as a form control, such as a text box or a select list. The visitor sets the value, submits the form and the list updates to match. Without exposing, the site builder fixes the filter value in the view, and nobody sees it.

How exposed filters work in Drupal 11

You expose a filter in Views UI. Open the view, click a filter in the Filter criteria section and click the Expose filter button in the dialog. The Drupal documentation then offers two types: a single filter, or grouped filters. Grouped filters allow a choice between predefined operator and value pairs.

The exposed filter form has these settings, all named in the core source:

  • Required. When the filter is not required, a single-choice select list gets an "- Any -" choice. A Views UI setting can change the label to "<Any>".
  • Allow multiple selections. Lets visitors pick several items.
  • Filter identifier. The name that appears in the URL after the question mark.
  • Remember the last selection. Keeps the visitor's choice. A separate User roles setting limits this to chosen roles; if no role is selected, the data is never stored.
  • Expose operator. Lets the visitor choose the operator, such as contains.

The behavior of the whole form comes from the exposed form style, set under Exposed form in the view. Core includes Basic and Input required. Input required renders the view only after the visitor has entered something, and shows text of your choice until then. The exposed form settings also include the submit button text and an optional reset button.

Example

You have a view of articles on a page at /articles. Add the filter Content: Title with the operator Contains, expose it and set the filter identifier to title. A visitor who types drupal and submits the form sees only articles with that word in the title. The address now ends in ?title=drupal, so the filtered list can be bookmarked and shared.

Common mistakes

  • Forgetting the block. With Exposed form in block set to Yes the form leaves the view. Views will not enable the block for you, so place it in the block layout.
  • Forgetting anonymous visitors. When you switch on Remember the last selection, the User roles setting has only the authenticated role selected by default. Anonymous visitors' choices are not stored until you add their role.
  • Renaming the identifier later. The identifier is part of the address, so changing it changes the addresses of the filtered lists.
  • Mixing up the two filter kinds. A filter the visitor cannot see is a contextual filter, not an exposed one.

For marketing and content teams

An exposed filter is a design choice for the reader: every control you add is one more decision on the page. Ask for the few filters your visitors need, give them plain labels, and say whether they should pick one value, several, or from a fixed set such as grouped choices. Agree on the identifier before launch if you plan to link to filtered pages from campaigns.

With DXPR

DXPR Builder can place a view on a page, so the list and its exposed form sit inside a visually built layout. The filter itself stays an ordinary Drupal view setting. See DXPR Builder.

Sources

Questions about Views exposed filters

An exposed filter shows a form control, and the visitor sets the value. A contextual filter is invisible: it takes its value from context such as the URL when the view runs. See contextual filters.

In the view, set Exposed form in block to Yes. The widgets then no longer appear with the view; Drupal offers a block for the form instead. You must place and enable that block yourself, because Views does not do it. The option is listed for displays that have a path.

Yes. Turn on Allow multiple selections in the exposed filter settings. For a fixed set of choices, use grouped filters instead: they offer a choice between predefined operator and value pairs.

Each exposed filter has a Filter identifier, and its description says it appears in the URL after the question mark. A search for drupal on a Title filter with the identifier title gives an address ending in ?title=drupal.

Related terms

All Drupal terms from A to Z