Forum
Search Filtering
Hi,
I'm just wondering whether I am missing a trick here, or have got things completely wrong but....
My aim is to have a search facility on the site. This is all working well, based of the supplied pages and modified templates, i.e. search.php, main-search-form.html and main-search-result.html.
The search bar is in the header of the site (within a layout file) and returns results currently just to the search.php page within the route and this works fine.
I have exposed the 'result-source' so the user can see where results are being pulled from, but what I would like to do is add a 'filter' on the search.php page, which would then return results based on this secondary request.
So, workflow would be. User submits initial search term (search=search-term), which is then displayed on the search.php page using:
<?php
$query = perch_get('search');
perch_content_search($query, array(
'template'=>'main-search-result.html'
));
?>
However, at the top of the search.php page, I would like to have a series of links, where I could then filter the delvierd results by the result-source, or rather app.
Just wondering if I can do this and how I could, as I cannot quite think through how I would still keep the 'search-term' and submit it once more into another perch query such as:
<?php
$query = perch_get('search');
perch_content_search($query, array(
'apps' => array('PerchBlog'),
'template'=>'main-search-result.html'
));
?>
I've tried a few things, but not even sure if this is possible.
Any ideas ?
Maybe I have to pass it to another page ? Bit lost.
Any help, greatly appreciated.
Ulitmately, I suppose trying to get to a button or link that would filter the current displayed results.
If I passed the query value into a new page then I could use a new perch call as above to 'filter' on apps, but wondering if I can keep it on the same page, maybe with an if/else statement to pick-up if a filter has been clicked ?????
Thanks.
The search term is in
perch_get('search')
so you need to append that to your link. For example:Before searching, check if
source
has a value.Remember if you're outputting anything to the page other than through a template you need to make sure you escape any user input.
Thanks Drew, I will have a go now and see if I can get it resolved.
Sorry Drew, that seems to slightly off and I cannot quite get why.
First error is:
The comma I have removed.
It seems to get stuck with:
Tried a whole bunch of things, but no joy.
Should be a
;
I had tried that. When added, I get:
I don't think I can debug this for you line by line without seeing it.
I've tried having a good go at this and still no joy. It all seems to stem from the IF statement.
In my search page, all I have done initially is to replace the my code with yours above. Even if I do not generate the '<a href' source link, the code should just return all results, i.e. unfiltered.
My page in it's most basic guise is:
Having tried lots of different ways, it seems that the issue lies with:
being within that statement. It just throws an error.
Even just having the if statement without any options does not parse.
Try this:
(missing a
)
on line 1)Thanks Duncan. Cannot believe I missed that ! Oh well, once again, thank you for replying.
All the best.