Why isn't my Shopify search function limiting results to products only?

zoombie
Visitor
2 0 4

Hello there,

 I'm using the Dawn theme, I want to make the search function to be only searching for products. After some research, I've found this code

<input type=hidden name=type value="product">

I've put it in this section of main-search.liquid

 <form action="{{ routes.search_url }}" method="get" role="search" class="search">
                      <input type=hidden name=type value="product">

          <div class="field">
            <input
              class="search__input field__input"
              id="Search-In-Template"
              type="search"
              name="q"
              value="{{ search.terms | escape }}"
              placeholder="{{ 'general.search.search' | t }}"
              {%- if settings.predictive_search_enabled -%}
                role="combobox"
                aria-expanded="false"
                aria-owns="predictive-search-results-list"
                aria-controls="predictive-search-results-list"
                aria-haspopup="listbox"
                aria-autocomplete="list" 
                autocorrect="off"
                autocomplete="off"
                autocapitalize="off"
                spellcheck="false"
              {%- endif -%}
            >

 

The code works half of the time. When searching using the search form in the header, it return results for everything. But on the search results page, there's another search form, if I search from that search form, the results is for product only.

Here's my website

www.ikuono.com - try searching "high top sneaker"

 

Thank you 🙂

Replies 6 (6)

PaulNewton
Shopify Partner
6274 573 1319

Improve  <input type=hidden name=type value="product">

to 

 <input type="hidden" name="type" value="product">

Helps remove the chance of parse errors

 

And try it again.

Save time & money ,Ask Questions The Smart Way


Confused? Busy? Get the solution you need paull.newton+shopifyforum@gmail.com


Problem Solved? ✔Accept and Like solutions to help future merchants

Answers powered by coffee Buy Paul a Coffee for more answers or donate to eff.org


zoombie
Visitor
2 0 4

Hi Paul,

 Did that, didn't work 😞

Xhale_City
Tourist
4 0 5

+1!!!
Can't get this to work in Dawn theme main-search.liquid code
Shopify .dev Docs don't have proper documentation for filtering search results on OS 2.0 Themes.

Xhale_City
Tourist
4 0 5

@zoombie I see you got this working on your site! Mind sharing your knowledge? Never mind, I see the page results at the bottom of the search now 😞

🙏🏼

Cyclops1717
Excursionist
33 0 13

@zoombie If you add the same code to the Header.liquid file, that will solve your problem.

Search in header.liquid for the same function (form action...) and add the same code Paul provided.

I've been trying to figure this out for 2 days... that solved it for me.

Chuckachucka
Excursionist
13 0 8

Hi all, the code has worked on Desktop view but not Mobile. Does anyone have a solution to fix this?