How to hide specific products from search in Dawn 15

I have found this code:

{% assign filtered_results = search.results | where_exp: “product”, “product.tags contains ‘exclude-from-search’ == false” %}

I have tagged all the products that I do not want displayed in search results with “exclude-from-search”.

I thought that this code should go in: main-search.liquid

But I can’t figure out where to put it. Nothing has worked so far.

1 Like

Hi I think I can help with that. If you’re still having issues, feel free to share more details.

Hello @modernmagic ,

The code will be used with the existing loop.

Check the search template for similar loop

starts with

{% for item in search.results %}
and ends with
{% endfor %}

now here you have to apply the logic.

Regards
Guleria

Hello @modernmagic
Welcome to the Shopify Community! Please share your store URL and password (if it’s password-protected), so I can check and provide you with the exact solution.

I’m looking for someone to tell me where to paste the code?

Hi, @modernmagic

  1. Step-by-step:
    Go to Online Store > Themes > Edit Code
  2. Open sections/main-search.liquid (or templates/search.liquid, depending on your theme)

Look for a loop like:

{% for item in search.results %}

Replace it with:

{% assign filtered_products = search.results | where: "object_type", "product" %}
{% assign visible_products = filtered_products | reject: "tags", "exclude-from-search" %}

{% for product in visible_products %}

{% render 'card-product', product: product %}
{% endfor %}

If you will unable to implement the same then I’m happy to do this for you, let me know.

Hope this helps! If yes then Please don’t forget hit Like and Mark it as solution!