Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

Form Questions /

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

How to limit search results


Go to End


2 Posts   1048 Views

Avatar
zim

Community Member, 135 Posts

29 June 2011 at 10:34pm

I need to limit my search results to just blog and newPage items. But can not find info on how to do this.

All i can find is stuff telling me to amend a function in Page.php. but there is no search function in page.php. I am using 2.4.

I hope this can be done. can anyone advise please. Much appreciated

Avatar
zim

Community Member, 135 Posts

29 June 2011 at 11:11pm

...ok i have found this.. which seems to work... but how do i limit to just blogs and newsPage items...

function results($data, $form){

$dosResults = $form->getResults();

$dosNewResults = new DataObjectSet();
foreach ($dosResults as $doResult)
{
if ( $doResult->URLSegment == "contact-us")
{
//filtered
}
else
{
//keep
$dosNewResults->push($doResult);
}
}

$data = array(
'Results' => $dosNewResults,
'Query' => $form->getSearchQuery(),
'Title' => 'Search Results'
);

$this->Query = $form->getSearchQuery();

return $this->customise($data)->renderWith(array('Page_results', 'Page'));
}