Exclude Pages in Store Search Results

rorydean
Shopify Partner
7 0 3

I am running Studio theme 4.0.0 and need to remove all pages from appearing in the store search results. Right now, pages appear in search results as a solid color card with a tag that says Page.  I have located what I believe to be the code referring to pages in the main-search.liquid file but I am unsure how much of the code should be removed without causing any problems. 

 

Ideally I would like to include only products in the search results.

I consulted the Storefront search FAQ pages but did not find it helpful: https://shopify.dev/themes/navigation-search/search#the-search-form

 

Thanks- 

Replies 4 (4)

PaulNewton
Shopify Partner
6274 573 1319

Check the object_type property on each result in the search.results array to see if it's a product.

https://shopify.dev/api/liquid/objects/search#search-results 

 

If in a loop just do the check then continue to the next loop

{%- if result.object_type != "product" -%}{% continue %}{%-endif -%}

 

 

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


rorydean
Shopify Partner
7 0 3

Thanks for that tidbit.  That's at least part of the puzzle.  

thebarebar
Visitor
1 0 0

did you manage to get a solution? I'm facing the same issue

rorydean
Shopify Partner
7 0 3

Hey @thebarebar  no direct solutions to my post...

 

But I went back to research and tracked down the information that I was looking for on how to exclude page results in the storefront search results for Studio 4.0.0 theme. 

 

I'll include a link here to the original post: Take a look at this thread from right here in the Shopify Community forum back in September of this year.  Another shout out to @VrVa and @Cedcommerce for their combined efforts.

 

I'm running Studio 4.0.0 theme, and the original notes were for Dawn 6.0.2 so make sure you understand the differences.  There are two parts to the solution for excluding page results from the storefront search results.  You'll need to edit your theme code, in particular your "main-search.liquid" file and create a custom metafield.  As VrVa points out, by using a custom metafield this will allow you to hide pages without having to edit code each time.  

 

Cheers-