Reference

$pages->filterBy()

Filters elements by one of the predefined filter methods.

$pages->filterBy(string $field, $args = null): Kirby\Cms\Pages

Parameters

Name Type Default Description
$field string
$args mixed null

Return type

Kirby\Cms\Pages

Example

// fetch children with a field 'draft', which has the value 'yes'
$items = $page->children()->filterBy('draft', 'yes');

// fetch children with a date in the past
$items = $page->children()->filterBy('date', '<', time());

// fetch children with a date in the future
$items = $page->children()->filterBy('date', '>', time());

// fetch any page with a project template
$items = $site->index()->filterBy('template', 'project');

// fetch any page with either an article or project template
$items = $site->index()->filterBy('template', 'in', ['article', 'project']);

// fetch children that have the tag 'development'
$items = $page->children()->filterBy('tag', 'development', ',');

// fetch children that have the tag 'development' from a tags field with separator ';'
$items = $page->children()->filterBy('tag', 'development', ';');

Available filter methods

Method Function
== all values that match exactly
in takes an array as parameter, matches all values that are included in the array
!= all values that don't match
not in takes an array as parameter, matches all values that are not included in the array
*= all values that contain the given string
> all values that are greater than the given value
>= all values that are greater or equal the given value
< all values that are smaller than the given value
<= all values that are smaller or equal the given value

Source code

kirby/src/Toolkit/Collection.php#L251