<p>Add this to your chain...</p>

<pre><code>.yourCategoryField(':notempty:')
</code></pre>

<p>It's not very well documented, but you can see it described in <a href="https://craftcms.stackexchange.com/a/453/45">this old SE thread</a>. In the docs, it's mentioned very briefly <a href="https://docs.craftcms.com/api/v3/craft-helpers-db.html#method-parseparam" rel="nofollow noreferrer">here</a>.</p>

CC BY-SA 4.0
2018-10-23T17:26:36.320Z
Hi Lindsey, Thanks for your answer.  Unfortunately, that would give me all entries that have a Category associated to it.  I want it the other way around.  I need all Categories that were assigned at least once somewhere.
Eric Chantigny
CC BY-SA 4.0
2018-10-23T16:47:36.547Z
2018-10-23T16:47:36.547Z
Lindsey D
<p>I'm looking for a way to query all categories that have at least one relation.  I'm not looking for the relatedTo() parameter, which would give me categories related to something specific.</p>

<p>Basically, if we talk in Wordpress terms, I'm looking for hideEmpty = true.</p>

<p>Is there anything like that in Craft?</p>

<pre><code>Something like: craft.categories.group('products').hasRelated()
</code></pre>

CC BY-SA 4.0
2018-10-23T19:13:14.197Z
To get this going, I used the cached loop through all the categories and using relatedTo(category) to create a cached list of IDs.
Based on this thread: https://craftcms.stackexchange.com/questions/11151/only-fetch-categories-that-are-related-to-a-minimum-of-entries?rq=1
Eric Chantigny
<templating><categories><query>
Is there a query parameter to get categories that are related to anything else?
# Is there a query parameter to get categories that are related to anything else?

(Asked by: username_0 on 2018-10-23)

I'm looking for a way to query all categories that have at least one relation.  I'm not looking for the relatedTo() parameter, which would give me categories related to something specific.
Basically, if we talk in Wordpress terms, I'm looking for hideEmpty = true.
Is there anything like that in Craft?
Something like: craft.categories.group('products').hasRelated()

**Tags:** templating, categories, query

> **Comments:**
> **username_0**: To get this going, I used the cached loop through all the categories and using relatedTo(category) to create a cached list of IDs. Based on this thread: https://craftcms.stackexchange.com/questions/11151/only-fetch-categories-that-are-related-to-a-minimum-of-entries?rq=1  

---

## 1 answers

### Answer by username_1 on 2018-10-23. Score: 1

Add this to your chain...
.yourCategoryField(':notempty:')

It's not very well documented, but you can see it described in this old SE thread. In the docs, it's mentioned very briefly here.

> **Comments:**
> **username_0**: Hi Lindsey, Thanks for your answer.  Unfortunately, that would give me all entries that have a Category associated to it.  I want it the other way around.  I need all Categories that were assigned at least once somewhere.  

---

