Hiding products from search

BelBren
Tourist
5 0 0

Hi, I am trying to hide certain products from the search function on my website. I have added a tag on all of these items, '_HIDDEN_PRODUCT', and am trying to edit the search.json file to not include product with this tag.

I have tried changing the if statement to {%- if result.object_type == 'product' && result.tags !contains '_HIDDEN_PRODUCT' -%}, which doesn't seem to work.

I have also tried other solutions such as surrounding it in if statements:

{%- if result.tags contains '_HIDDEN_PRODUCT' %-}

  {%- assign display = false %-}

{%- endif %-}

{%- if display == true %-}

 

and I have also tried the same implementation but iterating through the tags

 

{%- for tag in result.tags %-}

  {%- if tag contains '_HIDDEN_PRODUCT' %-}

 

etc.

 

Can anyone offer any advice on this? It would be much appreciated

 

Thanks.

Replies 3 (3)
Propero
Shopify Partner
884 101 155

Please use unless logically simple so you shouldn't have issues due to logic

{% if item.object_type == 'product' %}
{% assign product = item %}
{% unless product.tags contains '_HIDDEN_PRODUCT' %}
{% include 'product-grid-item' %}
{% endunless %}
{% else %}
// Usual code 
{% endif %}
- Was my reply helpful? Click Like or Click Accept as Solution
To hire: email us at shopify@propero.in
checkout our app https://apps.shopify.com/picamaze
Kuku
New Member
2 0 0

Hi!

I'm having a similar issue, just wondering where would you place this code? I'm using the Venture template.

Thank you!

BugShallNotPass
Excursionist
30 1 3

I've developed this app that does the job without modifying your theme code: https://apps.shopify.com/hide-from-search - check it out.

Xmas Shopify app - beautiful falling snow animation
New Arrivals Shopify app - automatically tag/untag products based on creation/publishing date
Motion - scrolling text announcements
Stash Shopify app - hide products from search results and search engines