<p>This doesn't work out of the box with Craft as the category field is a relation field.</p>

<p>However you should be able to use <a href="https://github.com/TopShelfCraft/SuperSort" rel="nofollow noreferrer">SuperSort</a> plugin.</p>

<pre><code>{% set products = craft.commerce.products.type('coins').limit(null) %}
{% set orderedProducts = products | supersort('sortAs', '{stateCat.first.stateImportance}' %}
</code></pre>

CC BY-SA 3.0
2017-06-15T09:35:01.363Z
2017-06-15T09:35:01.363Z
pauliusef
<p>All of my products have a category field called stateCat. These state categories have a field called stateImportance. This is because some states are more important than others and I want to sort the products based on that stateImportance number. I have no idea how to do this.</p>

<p>This is what I've tried:</p>

<pre><code>{% set products = craft.commerce.products.order('stateCat.stateImportance asc').type('coins').limit(null) %}
</code></pre>

<p>This doesn't seem to work, how can I accomplish this?</p>

CC BY-SA 3.0
2017-06-15T22:40:38.973Z
"This is because some states are more important than others". For example, any state is greater than Florida.
Brad Bell
CC BY-SA 3.0
2017-06-15T22:40:51.880Z
(Really hope you're not from Florida)
Brad Bell
CC BY-SA 3.0
2017-06-16T07:35:33.323Z
Im not from the US and I'm making a website with coins that are 200-300 years old. Coins from certain states in The Netherlands have more value than others. These have to be on top
Branko
<ordering><queries><order><products>
Sort products by category field value
# Sort products by category field value

(Asked by: username_0 on 2017-06-15)

All of my products have a category field called stateCat. These state categories have a field called stateImportance. This is because some states are more important than others and I want to sort the products based on that stateImportance number. I have no idea how to do this.
This is what I've tried:
{% set products = craft.commerce.products.order('stateCat.stateImportance asc').type('coins').limit(null) %}

This doesn't seem to work, how can I accomplish this?

**Tags:** ordering, queries, order, products
> **Comments:**
> **username_1**: "This is because some states are more important than others". For example, any state is greater than Florida.  
> **username_1**: (Really hope you're not from Florida)  
> **username_0**: Im not from the US and I'm making a website with coins that are 200-300 years old. Coins from certain states in The Netherlands have more value than others. These have to be on top  

---

## 1 answers

### Answer by username_2 on 2017-06-15. Score: 2 | Accepted answer

This doesn't work out of the box with Craft as the category field is a relation field.
However you should be able to use SuperSort plugin.
{% set products = craft.commerce.products.type('coins').limit(null) %}
{% set orderedProducts = products | supersort('sortAs', '{stateCat.first.stateImportance}' %}


---

