Reference

Guide

$pages->search()

Searches the collection

$pages->search(string $query = null, array $params = [ ]): Kirby\Cms\Pages

Parameters

Name Type Default Description
$query string null
$params array [ ]

Return type

Kirby\Cms\Pages

Parameter options and defaults

$defaults = [
  'minlength' => 2,
  'fields'    => [],
  'words'     => false,
  'score'     => []
];

Examples

// search all pages and descendants
$results = $pages->search('my awesome search');

// filter the search results
$results = $pages->search('my awesome search')->listed()->filterBy('template', 'article');

// add pagination to the search results
$results = $pages->search('my awesome search')->paginate(20);

// search in certain fields only
$results = $pages->search('my awesome search', 'title|text');

// search for full words only
$results = $pages->search('my awesome->search', ['words' => true, 'minlength' => 4]);

// feed the search with a get parameter -> http://yourdomain.com/?q=awesome
$results = $pages->search(get('q'));

Inherited from

Kirby\Cms\Collection

Source code

kirby/src/Cms/Collection.php#L286