I have a simple site-wide search page. In my search.php controller, I’m attempting to have the search NOT include a page (‘members’) and its children pages. I tried ‘not’ method and ‘not in’ but it still searches all of the pages.
Thank you for your quick response. I had to add the listed() method to be able to use the add() method. The page wouldn’t display even in debug mode. Not sure why that is because both the children() and listed() return the same type.
The above code works for the main page and its children, but it doesn’t exclude any grandchildren or any deeper subpages.
So I modified the code to use the index() method. That works. However, I know the index() method can be pretty heavy since it’s looking through the entire contents including files. Is there another way besides using that method to exclude the parent ‘members’ page and all of it’s subpages?
The warning basically refers to using $site->index() in large installations. Of course, if you your members page also has thousands of subpages in the tree, you might run into the same issue. I hope, that is not the case, otherwise, you will have to cache the collection.
A published page is a page that is either listed or unlisted and since drafts are not publicly accessible anyway, there is nothing special to do. Unless you mean only listed pages.
what do you mean with search code?
when i go to the website “www.mywebsite.de
/search?q=abc” i only want listed sites with “abc” shown.
is this, what you mean?
No, I mean the code that is responsible for showing the search result, probably a controller /site/controllers/search.php. You did not develop the site then?