Skip to content
← All posts

Visual Collection Filtering in Statamic Without Code

Your editors should not need a developer every time they want to filter a collection differently. Statamic Filter Builder adds a visual query builder to the control panel.

· 5 min read · Sylvester Damgaard
Visual Collection Filtering in Statamic Without Code

Every Statamic site eventually hits the same wall: an editor wants to show "the 5 most recent blog posts tagged with 'laravel' that have a featured image" on a page, and the developer has to write a custom query scope, deploy it, and hope the requirements don't change next week. When they do, the cycle repeats.

I built Statamic Filter Builder to break this cycle. It adds a visual query builder to the Statamic control panel that lets editors construct collection filters without writing code or waiting for a deploy.

The Problem

Statamic's {{ collection }} tag is powerful but developer-facing. To filter a collection, you either use inline parameters in your Antlers template:

antlers
{{ collection:blog taxonomy:tags="laravel" limit="5" sort="date:desc" }}

Or write a custom query scope in PHP:

php
class FeaturedLaravelPosts extends Scope
{
    public function apply($query, $values)
    {
        $query->where('featured_image', '!=', null)
              ->whereTaxonomy('tags', 'laravel')
              ->orderBy('date', 'desc')
              ->limit(5);
    }
}

Both approaches require a developer. The template approach means editing code. The query scope approach means writing PHP, registering the scope, and deploying. For a CMS that prides itself on empowering editors, this is a gap.

How Filter Builder Works

Filter Builder introduces two modes for defining filters: config mode for developers who want reusable filter presets, and field mode for editors who want to build filters visually.

Config Mode

In config mode, you define named filter presets in a YAML configuration file:

yaml
filters:
  recent_laravel:
    collection: blog
    conditions:
      - field: taxonomy:tags
        operator: contains
        value: laravel
      - field: featured_image
        operator: is_set
    sort: date:desc
    limit: 5

These presets can be referenced in your templates by name:

antlers
{{ filter_builder:recent_laravel }}
  

{{ title }}

{{ excerpt }}

{{ /filter_builder:recent_laravel }}

This is useful for developers who want to define common filters once and reuse them across templates without duplicating query logic.

Field Mode

Field mode is where editors get their power back. Filter Builder adds a custom fieldtype that renders a visual query builder directly in the Statamic control panel. Editors can:

  1. Select a collection from a dropdown

  2. Add conditions by picking a field, an operator, and a value

  3. Chain conditions with AND/OR logic

  4. Set sorting by any field, ascending or descending

  5. Set a limit on the number of results

The fieldtype stores the filter configuration as structured data in the entry's YAML front matter. In your template, you render the results with the Filter Builder tag:

antlers
{{ filter_builder :source="filter_field_handle" }}
  

{{ title }}

{{ /filter_builder }}

The tag reads the filter configuration from the field, builds the query, and returns the matching entries. No PHP, no query scopes, no deploys.

Dynamic Variables

Filters can reference the current entry's data using dynamic variables. For example, to show "related posts with the same tags as this post":

In the control panel, the editor sets a condition:

  • Field: taxonomy:tags

  • Operator: contains any

  • Value: {{ tags }} (dynamic, references the current entry)

The filter resolves {{ tags }} at render time, pulling the value from the current entry's context. This enables dynamic "related content" blocks without any code.

Other useful dynamic variables:

  • {{ now }} for date-relative filters ("posts from the last 30 days")

  • {{ segment_1 }} for URL-aware filtering

  • Any field from the current entry's data

Operators

Filter Builder supports the operators that editors actually need:

Operator

Description

Example

is

Exact match

Status is "published"

is_not

Not equal

Author isn't "admin"

contains

String contains

Title contains "Laravel"

is_set

Field has a value

Featured image exists

is_not_set

Field is empty

No excerpt set

before

Date is before

Published before 2025-01-01

after

Date is after

Published after today

greater_than

Numeric comparison

Reading time > 5

contains any

Taxonomy overlap

Tags contains any of [laravel, php]

Operators are validated against the field type, so editors can't accidentally create invalid filters like "date contains php."

Performance

Filter Builder generates Statamic query builder calls, not raw SQL. This means it benefits from Statamic's built-in caching and optimization. Filters are resolved at render time and cached according to your Statamic cache configuration.

For sites with large collections (1000+ entries), I recommend using config mode with explicit indexes or combining Filter Builder with Statamic's static caching. The visual query builder adds no runtime overhead beyond the query itself.

Full documentation including all operators, dynamic variables, and template examples is in the Filter Builder docs.


// Sylvester Damgaard