All things Shopify and commerce
Hello,
I'm building a Liquid page template to get collections with a single text line metafield Page Type "Shop By Make". However, it is returning as "No collections found."
Below is my code:
<div class="shop-by-make-container"> <h1>Shop By Make</h1> {% assign filtered_collections = collections | where: "collection.metafields.custom.page_type.value", "Shop By Make" %} {% assign sorted_collections = filtered_collections | sort: "title-descending" %} {% if sorted_collections.size > 0 %} <ul class="shop-by-make-list"> {% for collection in sorted_collections %} <li class="shop-by-make-item"> <a href="{{ collection.url }}"> {% if collection.metafields.custom.thumbnail_image %} <img src="{{ collection.metafields.custom.thumbnail_image | img_url: 'medium' }}" alt="{{ collection.title }}"> {% else %} <img src="{{ collection.image | img_url: 'medium' }}" alt="{{ collection.title }}"> {% endif %} <p>{{ collection.title }}</p> </a> </li> {% endfor %} </ul> {% else %} <p>No collections found.</p> {% endif %} </div>
Found my reply helpful? Click Like to let me know!
Got your question answered? Mark it as an Accepted Solution.
Interested in working together? Contact Us Now!
Hi @paulrainstorm ,
There is an issue in syntax.
Please try the below code:
<div class="shop-by-make-container">
<h1>Shop By Make</h1>
{% assign filtered_collections = collections | where: "metafields.custom.page_type.value", "Shop By Make" %}
{% assign sorted_collections = filtered_collections | sort: "title" %} <!-- Sorting corrected -->
{% if sorted_collections.size > 0 %}
<ul class="shop-by-make-list">
{% for collection in sorted_collections %}
<li class="shop-by-make-item">
<a href="{{ collection.url }}">
{% if collection.metafields.custom.thumbnail_image %}
<img src="{{ collection.metafields.custom.thumbnail_image | img_url: 'medium' }}" alt="{{ collection.title }}">
{% else %}
<img src="{{ collection.image | img_url: 'medium' }}" alt="{{ collection.title }}">
{% endif %}
<p>{{ collection.title }}</p>
</a>
</li>
{% endfor %}
</ul>
{% else %}
<p>No collections found.</p>
{% endif %}
</div>
Hope this helps. Let me know if you need more help.
Regards,
Dotsquares Ltd
Problem Solved? ✔ Accept and Like solution to help future merchants.
Please try this code
<div class="shop-by-make-container">
<h1>Shop By Make</h1>
{% assign filtered_collections = collections | where: "metafields.custom.page_type", "Shop By Make" %}
{% assign sorted_collections = filtered_collections | sort: "title" | reverse %}
{% if sorted_collections.size > 0 %}
<ul class="shop-by-make-list">
{% for collection in sorted_collections %}
<li class="shop-by-make-item">
<a href="{{ collection.url }}">
{% if collection.metafields.custom.thumbnail_image != blank %}
<img src="{{ collection.metafields.custom.thumbnail_image | img_url: 'medium' }}" alt="{{ collection.title }}">
{% elsif collection.image %}
<img src="{{ collection.image | img_url: 'medium' }}" alt="{{ collection.title }}">
{% endif %}
<p>{{ collection.title }}</p>
</a>
</li>
{% endfor %}
</ul>
{% else %}
<p>No collections found.</p>
{% endif %}
</div>
I hope this helps
Best,
Daisy
Shopify and our financial partners regularly review and update verification requiremen...
By Jacqui Mar 14, 2025Unlock the potential of marketing on your business growth with Shopify Academy's late...
By Shopify Mar 12, 2025Learn how to increase conversion rates in every stage of the customer journey by enroll...
By Shopify Mar 5, 2025