<p>To get all categories that are related to an entry you would do this:</p>

<pre><code>{% set allEntries = craft.entries.limit(null) %}
{% set categoriesInUse = craft.categories.relatedTo(allEntries) %}
</code></pre>

<p>If you want to narrow down to a specific category group or any other category property you can do it like so:</p>

<pre><code>{% set newsCategories = craft.categories.group('newsCategories').limit(null) %}
{% set entriesWithNewsCategories = craft.entries.relatedTo(allCategories).limit(null) %}
{% set newsCategoriesInUse = craft.categories.relatedTo(entriesWithNewsCategories) %}
</code></pre>

<p>And yes, you probably want to wrap it together with the loop to print the categories in cache tags!</p>

CC BY-SA 3.0
2015-01-22T22:21:32.303Z
2015-07-20T15:40:55.483Z
2015-07-20T15:40:55.483Z
carlcs
<p>In other words, categories must have at least one enabled entry assigned to them.</p>

<categories><elementcriteriamodel>
How can I output a list of categories that are not empty?
# How can I output a list of categories that are not empty?

(Asked by: username_0 on 2015-01-22)

In other words, categories must have at least one enabled entry assigned to them.

**Tags:** categories, elementcriteriamodel


---

## 1 answers

### Answer by username_1 on 2015-01-22. Score: 6

To get all categories that are related to an entry you would do this:
{% set allEntries = craft.entries.limit(null) %}
{% set categoriesInUse = craft.categories.relatedTo(allEntries) %}

If you want to narrow down to a specific category group or any other category property you can do it like so:
{% set newsCategories = craft.categories.group('newsCategories').limit(null) %}
{% set entriesWithNewsCategories = craft.entries.relatedTo(allCategories).limit(null) %}
{% set newsCategoriesInUse = craft.categories.relatedTo(entriesWithNewsCategories) %}

And yes, you probably want to wrap it together with the loop to print the categories in cache tags!


---

