Possible to search multiple pages at once?


#1

I’m trying to make a search option which let’s you filter the search results by certain (user selected) pages that but I can’t seem to be able to make a collection which would work for the search() function? The pages could be a mix of top level pages and subpages so for example: content/01-news/ and content/02-support/01-docs/

Is this possible somehow?


#2

you can filter your collection prior your search first, there’s many different operators to use…

https://getkirby.com/docs/cheatsheet/pages/filter-by

<?php 
$site->index()->filterBy('template','==', 'some-template')->search(...)
$site->index()->filterBy('field','==', 'some-value')->search(...)
?>

#3

If filtering is not sufficient, you can merge collections or add pages to a selection prior to using the search method.


#4

Should the search method work if I’ve created my own collection like this?

$pagescollection = new Collection();

and then appended data into it?


#5

You need an object of type Pages; so you can do:

$pagescollection = new Pages();

and then append to it.