As is it mentionned in the title, I would like to make a search function, excluding multiples pages.
I tried to make one by copying a thread I found here, but I’m not sure this is the right method : instead of ignoring some pages, I try to filterBy the pages where the search needs to be executed.
Based on my own search that filters out certain pages by template, try this… amend ‘title|text’ for the names of the content fields you want to search through…
<?php
return function($site, $pages, $page) {
// Search Results
$query = get('results');
// Filter the result....
$results = $site->search($query, 'title|text')->visible()->filterBy('template', 'not in', ['works', 'bio']);
// Pass these off to the template
return compact('query', 'results');
};
It makes more sense to limit the pages first, then search. Otherwise, you search within pages that you don’t even have to touch. @oziris Your logic is the wrong way round, because you want to exclude those pages, not use only those pages.