
Editorial illustration; the URL, user and results are representative examples, not a live Drupal administration screen.
A regular filter in Drupal Views answers a static question: show published nodes, show items of type Article, or exclude archived records. A contextual filter answers a dynamic question: show articles matching the topic in the current URL, show items authored by the logged-in user, or show related resources for the node currently being viewed.
That flexibility lets one View power dozens of category pages, author dashboards, and sidebar blocks. The trade-off is that you are now accepting an input from the URL or runtime environment—which means you have to define what happens when that input is missing, malformed, or points to something the visitor is not allowed to see.
Regular filters vs. contextual filters
Think of regular filters as your non-negotiable baseline (“which records are eligible at all?”) and contextual filters as the slice (“which subset belongs on this page?”).
The strongest Views always combine both. Even if a URL like /articles/topic/cloud passes the topic name into a contextual filter, keep Published = Yes and Content type = Article as regular filters. Never rely on a URL argument to enforce publication status or content-type boundaries.
Before opening the Views UI, spell out the contract in one sentence: “This display receives a taxonomy term ID from the URL path /articles/% and returns published help articles tagged with that term.” Naming the exact type (term ID vs. term name slug, node ID vs. user ID) prevents mismatched expectations later.
Setting up a contextual filter in Views
In your View display, expand the Advanced column on the right and click Add next to Contextual filters. Select the field or property that holds the value you want to match—for example, Content: Has taxonomy term ID or Content: Authored by.
Two configuration sections inside that modal determine whether the View behaves reliably in production:
When the filter value is NOT available
This setting controls what happens when no argument is passed—which is almost always true for Block displays placed on a node page, because blocks do not own the URL route the way Page displays do.
- For a Page display at
/articles/%, you might choose Display “No results found” or Show “Page not found” if a missing argument should not dump the entire unfiltered database onto the screen. - For a Block display showing related posts on a node page, choose Provide default value and pick Content ID from URL (or Taxonomy term ID from URL, or User ID from logged in user depending on the context).
Avoid leaving this on “Display all results for the specified field” unless an unfiltered list is genuinely what you want; on large sites, accidentally rendering every node in a sidebar block is an easy way to hurt page performance.
When the filter value IS available
Enable Specify validation criteria whenever the argument comes from a URL segment. Choose the validator that matches your input—such as Taxonomy term (and pick the specific vocabulary) or Content (restricted to your target bundle).
If you want readable URLs like /articles/web-security instead of /articles/14, set the Taxonomy term validator’s filter value type to Term name converted to Term ID and check Transform dashes in URL to spaces in term name filter values. Set Action to take if filter value does not validate to Show “Page not found” or Display “No results found” so random URL guesses return a clean 404 or empty state instead of a broken listing.
Relationships, duplicates, and cache contexts
Sometimes the value you want to filter by is not directly on the node—for instance, filtering articles by a field on the author’s user profile or a referenced organisation entity. In those cases, add a Relationship under Advanced first, then attach the contextual filter to that relationship.
Check the preview immediately after adding a relationship. Joining through a multi-value entity reference field can easily duplicate rows in the output. Also remember that a contextual filter does not replace Drupal’s access control: always test the View as an anonymous user and a standard authenticated user, not just User 1 or an administrator, to verify unpublished or restricted nodes never leak through.
Finally, pay attention to cache contexts. If a contextual filter uses User ID from logged in user, Drupal needs the user cache context (which Views normally adds automatically for user-based default values). Verify in testing that User A never sees User B’s cached contextual block.
Testing the full input matrix
Before placing a contextual View on a live route, test more than the happy path in the Views preview and on the actual page route:
- A valid value that returns multiple rows (check pagination and links).
- A valid value that returns zero rows (verify your empty-state text).
- No value at all (especially for Block displays placed via Block Layout or Layout Builder).
- An invalid or nonexistent slug/ID (confirm it triggers your chosen 404 or empty fallback).
- A value targeting unpublished or restricted content while logged out.
For related Drupal setup and caching guides, see:
- How to Set Up Drupal and MySQL on Your Local Machine Using Docker: A Complete Step-by-Step Guide
- Drupal Changes Are Not Showing? How to Troubleshoot Cache Without Clearing Everything
- Drupal Configuration Changes Should Travel as Code: A Safer Deploy Workflow
Treat every contextual filter as an input contract: define where the value comes from, validate its type, handle missing or invalid values deliberately, and test the real route across roles before shipping.