Collection with a tag that "does not contain" rule

Fish_off_the_Be
Excursionist
16 0 6

Hello,

I have some tags with a specific character in them, an underscore. For example, "style_something, style_somethingelse, texture_blahblah".

Other products do not have these kinds of tags. I'd like to have a smart collection display these products, which do not contain an underscore in their tags.

However while building a smart collection, I see it only allows 'whole-word' tag rules, instead of searching within the tag string. So I cannot search for tags containing just an underscore.

Is there a way to do this in Liquid?

Thanks!

0 Likes
Jenn_Seeley1
Shopify Staff (Retired)
Shopify Staff (Retired)
114 0 19

Hey there :) 

If you open any one of your products, and see the line for tags on the right hand side, you'll also notice an option to view all tags. This will show you all of your options - with and without the underscores. You could use this as a guide to take note of the tags you wish to include in a smart collection - but you'd need to add any new tags you create going forward to that collection if you wanted to include them there. There's not a way to create a rule like you're looking for sadly! 

Jenn

0 Likes
Fish_off_the_Be
Excursionist
16 0 6

Hey Jenn, thanks for the prompt response.

What you propose involves a ton of manual management, and made that much more difficult if a site makes real use of tags. What I mean by real use of tags is... regardless of what's going on in the rest of the system... a piece of content should be tagged with appropriate descriptive keywords. So in practice any product/page/blog posting may have 5-10 tags each, some being repeated across other content, some not.

You are correct, it does not seem possible to create a sub-string rule for tags in Collections. Funny enough, you can do a sub-string rule for titles. Kind of ridiculous?

Anyways, I'd rather not try to hold custom characters/codes/numbers in my product titles, and I'd like to continue using descriptive keyword tags.

Here is a solution via theme customization, that works for my specific request (filtering products by sub-string in tags):

1 - I made a Collection called "ALL" which covers all products. I simply went with one rule: "Vendor equals X". It works in our case because all of our products come from one vendor. Another store may have to figure out a different rule to cover all products. This will be my catch-all collection to make custom administration pages.

2 - I made a new template called "Collection_All" solely for the purpose of rendering that "ALL" collection in whatever way I wanted to. I did this by going to the Theme editor and clicking "Add a New Template" under templates. I based it off the existing Collection template.

2b - Afterwards, I also made sure to go back to Collections and set the "ALL" collection to use this new template. Now my customization will not affect the rest of the website experience.

3 - Using code from Shopify's own documentation on the "contains" operator, I created the following code, in place of the existing loop in the template:

{% for product in collection.products %}

  {% assign underscore = false %}

  {% for t in product.tags %}
    {% if t contains '_' %}
      {% assign underscore = true %}
    {% endif %}
  {% endfor %}

  {% if underscore == false %}
    {% include 'product-grid-item' %}
  {% endif %}

{% endfor %}

4 - I noticed this doesn't really work unless the Collection I made is set to Public. However, I don't necessarily want this Collection to be publicly accessible and displayed in any kind of Collections listing... I just want it for Admin use only. I may have to put some kind of code somewhere like "unless collection.title = 'ALL' " in a Theme file, didn't look into it yet.

 

Ultimately the only reason to make an "ALL" Collection and a custom template is because we cannot access the product database globally (ultimately part of Shopify's business model it seems). The only time when collection or product data can be accessed in code is when the browser has loaded a Collection (ie browser url "xxxxx.com/Collection").

 

BagBuff
New Member
1 0 0

I see this is from 2015, but OP has a good point, and I see this still hasn't been implemented.

We should be able to use "Product Tag > Does Not Contain" when creating collections. I had to go in and add a tag to over 50 products with an additional tag to differentiate these products when all I needed was the ability to use "Product Tag > Does Not Contain = {example tag}". Pretty silly.

This is a simple query feature that would save us a lot of time. I wasted an hour updating my Product Line Master import spreadsheet that will make this work. Every time my store needs a new tag to differentiate Collections I'll be wasting this hour.

0 Likes
PaulNewton
Shopify Partner
2775 155 513

@BagBuff wrote:

all I needed was the ability to use "Product Tag > Does Not Contain = {example tag}". Pretty silly.

This is a simple query feature that would save us a lot of time.


It's neither silly nor simple, saying either doesn't make it so.

To get this feature more merchants need to request it and there needs to be use cases: why can't you tag a product like normal,etc.


@BagBuff wrote:

This is a simple query feature that would save us a lot of time. I wasted an hour updating my Product Line Master import spreadsheet that will make this work. Every time my store needs a new tag to differentiate Collections I'll be wasting this hour.


Excel however excels at using your compute power for filtering text and has many approaches https://www.google.com/search?q=excel+filter+column+does+not+contain 

If your doing this enough that an hour is a worry you need to create formulas , filters,  scripts or macros to make better use of time.

A workaround for advanced users with small inventories is similar to the previous posters use of liquid: make a utility theme to spit out a list or products in the needed format though keep in mind pagination limits mean you may need to use javascript for more than 50 items at a time.

 

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
Suricata
Excursionist
20 0 3

OMG i miss this functionality too!

For my shop I need to check if all products have tag A or tag B, all products need to have one of those. It would have been so convenient to have a collection showing products that I have forgotten to tag. Sure, I can export to excel but I have more than 4000 articles and it makes the files quite large/slow...

0 Likes