Hide Products from Search Results based on Product Tag

Highlighted
Excursionist
21 0 7

I'm trying to hide products with the tag 'xsearch' from the search results on my store. I've tried editing the search.liquid file with something like this:

{% for item in search.results %}
{% if item.product.tags == 'xsearch' %}
{% else %}
{% include 'search-result' %}
{% endif %}
{% endfor %}

The search results page still shows products with this tag, and also produces an error that it "can't find 'snippets/search-result'" or something like that.

It sure would be nice for Shopify to include a check button that just allowed us to hide products from search right there on the product admin page. This seems unnecessarily complicated.

Any suggestions are welcome.

2 Likes
Highlighted
Shopify Staff
Shopify Staff
75 0 19

Hey there Jody!

Wesley here with the Shopify Guru team. 

I have an easier method for you to try there, instead of using an "if" statement, try using an "unless" statement that you would put right under {% for item in search.results %}

So it would be something like this:

...

{% for item in search.results %}

{% unless item.product.tags contains 'xsearch' %}

...

As for the: {% include 'search-result' %} If you put that in there, I would actually take that out. It is trying to use a snippet that I'm guessing you didn't put in??

Let me know how that works!

-Wesley

0 Likes
Highlighted
Excursionist
21 0 7

*EDIT 4/6/16: this actually didn't work, but I thought it was working for a brief moment.

Your suggestion worked perfectly! I'm more of a front end developer and I'm just now learning liquid. Thanks for the guidance.

Also, you were correct about the snippet. I had actually omitted that during my workflow after I posted this, seeing that the code was calling for an file/snippet that didn't exist (it's borrowed from a stack overflow thread).

0 Likes
Highlighted
Excursionist
21 0 7

Well, nevermind. It worked for one search, but it didn't work for further searches. Any idea why?

0 Likes
Highlighted
Excursionist
21 0 7

These "unless" statements are not working. I've tried product collections, I've tried tags, I've even tried titles. The search.liquid file is still letting search results come through that blatantly infringe on these conditions.

Does anyone know how this could happen? I am placing a condition directly under {% for item in search.results %} that is being completely ignored.

HALP! HAAAALLLP!!!

1 Like
Highlighted
Excursionist
21 0 7

I could really use help on this. If anyone happens upon this thread again.

0 Likes
Highlighted
Shopify Partner
2163 102 307

HALP! HAAAALLLP!!!

If this impacts your business hire someone, either through the experts page or in the forum job-board. These are user to user forums all volunteer.

Provide code(formatted) you are using, list website(provide storefront password if needed), list theme name.

For any steps tried provide urls for others to replicate non-working steps.

Create a reduced test case as able.

Problem Solved? ✔️Accept and ? Like the solution so you can help others.
Buy me a coffee ☕ paypal.me/paulnewton or donate to eff.org
Confused? Busy? Buy a custom solution paull.newton+shopifyforum@gmail.com
0 Likes
Highlighted
Excursionist
32 0 16

Yeah, I just tried this too. I thought hers didn’t work because she didn’t close the UNLESS statement but I did that and search still reveals items with the "xsearch" tag.

0 Likes
Highlighted
Excursionist
32 0 16

So frustrating. I tried it every way I can think of  

{% if item_type contains 'Product' and item.product.tag != 'xsearch' %}

from everything I read, that should work. But clearing cache in another browser — still when I search for any items with “xsearch” as a tag… THEY STILL SHOW UP. Why would this be? It almost has me thinking that this is not the liquid file that the search really uses.

0 Likes
Highlighted
Excursionist
32 0 16

Am I doing something wrong? I just added this code and got an error — as I expected: 

{% elephant farts %}

and emptied cache, reloaded and search and everything still working fine. Is my edited file not implemnented live somehow? It is like no matter what code I put in there is no effect live.

0 Likes