We're moving the community! Starting July 7, the current community will be read-only for approx. 2 weeks. You can browse content, but posting will be temporarily unavailable. Learn more

Re: How can I exclude variants from being included during search? Trade Theme, Search & Discover

How can I exclude variants from being included during search? Trade Theme, Search & Discover App

Geordie-JVT
Tourist
7 1 2

Hello,

 

I am currently using the Trade theme and the Shopify Search & Discover app. I am trying to prevent search from including variants when searching. For clarification, searching "silver" shows every single painting because they all have silver frame variants. When clicking on it, it has one of the silver frames pre-selected instead of the default unframed option. Is there a way to change this behavior? Thanks.

 

Screen Shot 2024-10-28 at 11.58.46 AM.png

Screen Shot 2024-10-28 at 11.58.54 AM.png

Screen Shot 2024-10-28 at 12.00.27 PM.png

Replies 2 (2)

BlackCro
Shopify Partner
103 19 19

One way to achieve this would be to add title: to the name parameter of the search form in main-search.liquid and header-search.liquid. This would limit the search term to the Product, Page or Blog title only excluding product variants from the results.  

 

Screenshot 2024-10-31 at 10.33.27.png

This wouldn't stop the results from showing in predictive search if you're theme uses them. I've not had time to dig into how that works, but i'm sure it would be something that could be done if needed. 

 

Hope this helps

Simon 

BlackCro.co.uk

CRO & Development Agency



Better Forms - Get a better contact form today!
BlackCro
Shopify Partner
103 19 19

Upon further testing this solution may not be producing the desired result. 

 

A current work around is to use an unless statement within the search results for loop targeting the product variant title. This successfully filters the displayed results, however, it can leave ghosted products which will continue to be paginated for larger result sets. I'm yet to find a neat solution to that, but I'll continue to work on it. 

 

{%- for item in search.results -%}
                  
{% assign downcaseTerms = item.selected_or_first_available_variant.title | downcase %}
{% unless downcaseTerms contains search.terms %}

 

BlackCro.co.uk

CRO & Development Agency



Better Forms - Get a better contact form today!