Skip to content

[6.x] Fix field filters returning all results when filtering by 0#14747

Open
joshuablum wants to merge 2 commits into
6.xfrom
fix-0-value-in-cp-filters
Open

[6.x] Fix field filters returning all results when filtering by 0#14747
joshuablum wants to merge 2 commits into
6.xfrom
fix-0-value-in-cp-filters

Conversation

@joshuablum
Copy link
Copy Markdown
Member

On listing views filtering a field using 0 as the value returns items as no filter was being used instead of matching ones with an actual value of 0.

Example: A text or integer field like Levels containing values like 0, 1, 2, 3, filtering for 0 ignores the filter entirely and returns all entries.

Statamic\Query\Scopes\Filters\Fields\FieldtypeFilter::isComplete() does $values = array_filter($values) where array_filter() with no callback removes every falsy element including both the string '0' and integer 0. With the value stripped, isComplete() returns false and never applies the filter.

The fix is to replace array_filter() with explicit checks, so 0 and '0' are treated as actual values while actual empty filters (null, '') are skipped.

Related:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant