0

How would I enable search in a single section only?

I want my search results template to be used regardless of which search option is used. Ideally I'm looking to pass another value from my search form to the search results to do

{% paginate craft.entries.search(query).section(sectionPassedFromSearchForm).limit(5) as entries %}

1

You would just pass the other value (i.e. the section handle) in to that template as GET or POST parameter and in the search results template grab the paramater and use it, as in your code.

If using GET, the url you'd construct would be something like:

http://whatever.com/search?query=blah&sectionHandle=blah2

or with POST you might use e.g. a radio for the section option with the name being sectionHandle and the value being the actual handle of the chosen section.

Either way, in your template you then just:

{% set sectionHandle = craft.request.getParam(sectionHandle) %}
{% paginate craft.entries.search(query).section(sectionHandle).limit(5) as entries %}
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.