Skip to content

Kirby 3.6.6

$pages->search()

Searches the collection

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

Parameters

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

Return type

Kirby\Cms\Collection

This method does not modify the existing $pages object but returns a new object with the changes applied. Learn more →

Parent class

Kirby\Cms\Pages inherited from Kirby\Cms\Collection

Parameter options

Option Default Description
minlength 2 Minimum length of search word
fields [] Fields to search in, defaults to all fields
words false Search full words only
score ['id' => 64,'title' => 64] Score per field
stopwords [] Array of words to exclude from search

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'));