Jump to:

1971 Posts in 1275 Topics by 607 members

Form Questions

SilverStripe Forums » Form Questions » How to limit search results

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

Page: 1
Go to End
Author Topic: 516 Views
  • zim
    Avatar
    Community Member
    135 Posts

    How to limit search results Link to this post

    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

  • zim
    Avatar
    Community Member
    135 Posts

    Re: How to limit search results Link to this post

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

    516 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.