FROM CACHE - en_header

Only search for products

zoombie
New Member
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
4335 322 932

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.

Finally Combinable Discounts - EARLY ACCESS ONLY - Use Free Shipping With Other Discounts

Answers powered by coffee Buy Paul a Coffee for more answers or donate to eff.org
Problem Solved? ✔Accept and Like solutions to help future merchants
Confused? Busy? Buy a custom solution paull.newton+shopifyforum@gmail.com
zoombie
New Member
2 0 4

Hi Paul,

 Did that, didn't work 😞

Xhale_City
Tourist
4 0 1

+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 1

@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
20 0 6

@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?