ideas icon indicating copy to clipboard operation
ideas copied to clipboard

Support OR Logic in API Query Filters

Open BobWez98 opened this issue 5 months ago • 0 comments

Currently, the Statamic REST API supports filtering entries via query parameters such as:

/api/collections/blog/entries?filter[title:contains]=duplicated&filter[introduction:contains]=test

However, when using multiple filters, they are combined using AND logic. In many use cases, it is necessary to apply OR logic instead, for example, searching multiple field values for a query.

Proposed Solution: Introduce a syntax or mechanism to group filters using logical OR. Some possible approaches:

Allow nested filter groups:

filter[or][0][title:contains]=duplicated&filter[or][1][introduction:contains]=test

Or support a pipe in the field selection:

filter[title|introduction:contains]=test

Example scenario: A search form where users want to find blog entries that contain the word "duplicated" in either the title or the introduction. The current API forces us to either:

  • Fetch all entries and filter client-side (inefficient),
  • Build a custom Laravel endpoint (adds maintenance burden).

Benefits:

  • Enables more flexible search queries
  • Improves API usability for headless
  • Reduces the need for custom endpoints and duplication of logic

BobWez98 avatar Jul 17 '25 09:07 BobWez98