Truly fine

Documentation.

Apply Search Behavior settings to Search page

Last update:

By default, the theme’s Search Behavior settings only apply to the search bars that display dynamic product suggestions. Namely, the search bar on the theme’s header, and the one on the search page (when it doesn’t show any results).

It may desirable to apply the same Show unavailable products and Result types settings on the Search page template, so that you have similar results in both areas, e.g. show pages but hide articles.

To do so, edit the theme’s file and create a new file inside the snippets folder, named search-parameters.liqud

Inside the file, paste the following:

{% comment %}
	Renders the hidden search form fields.

	Accepts:
	- form: {String} Optional. Form element ID

	Usage:
	{% render 'search-parameters', form: 'FacetsFilterForm' %}
{% endcomment %}

{%- capture result_types -%}
	product
	{%- if settings.predictive_search_articles -%},article{%- endif -%}
	{%- if settings.predictive_search_pages -%},page{%- endif -%}
{%- endcapture -%}
<input type="hidden" name="type" value="{{ result_types }}" {% if form != blank %}form="{{ form }}"{% endif %}>
<input type="hidden" name="options[unavailable_products]" value="{{ settings.predictive_search_unavailable }}" {% if form != blank %}form="{{ form }}"{% endif %}>

Now, edit snippets/header-search.liquid and locate the following line:

<input type="hidden" name="options[prefix]" value="last">

Immediately after it, paste the following:

{% render 'search-parameters' %}

Next, edit sections/main-search.liquid and locate the following line:

<input name="options[prefix]" type="hidden" value="last">

Immediately after it, paste the following:

{% render 'search-parameters' %}

On the same file, locate the line:

<input name="options[prefix]" type="hidden" value="last" form="FacetsFilterForm">

Paste this after it:

{% render 'search-parameters', form: 'FacetsFilterForm' %}

Your search page should now respect the Show unavailable products and Result types options.

Note: As the dynamic product suggestions area and the search page template area have different capabilities, it’s not possible to display exactly the same things in both areas. Specifically, the search page template can only display products, pages and articles, while the dynamic product suggestions area can also display collections and search suggestions in addition to the rest.

Can't find what you are looking for? Feel free to submit a request.