<p>Your mention tags, but it seems like you're merging Categories and Tags together and trying to loop through the results.</p>

<p>If you leave Categories out of the equation it's as simple as <a href="http://buildwithcraft.com/help/active-tags" rel="nofollow">this</a>.</p>

<p>If you want Categories and Tags, you'd repeat that process twice and merge the results.</p>

<p>Note that using <a href="http://twig.sensiolabs.org/doc/filters/merge.html" rel="nofollow">|merge</a> on full-fledged arrays of objects is sketchy, though, since it's difficult for PHP to know how to compare the objects for equality.  You'll be much better off merging on something primitive, like an array of element IDs.</p>

<p>Something like:</p>

<pre><code>{% set categoryIds = craft.categories.group('storiesCategories').ids() %}
{% set tagIds = craft.tags.group('storiesTagGroup').ids() %}
{% set elementIds = categoryIds|merge(tagIds) %}
</code></pre>

CC BY-SA 3.0
2015-10-26T17:58:06.010Z
2015-10-26T18:02:00.603Z
2015-10-26T18:02:00.603Z
Brad Bell
<p>Looking to loop through tags from entries but limit to only show tags that are being used on entries. Right now this just loops through any and all created tags.</p>

<p>I tried limit to null but have had no luck getting that to work.</p>

<pre><code>{% set categories = craft.categories.group('storiesCategories').find %}
{% set tags = craft.tags.group('storiesTagGroup').find %}
{% set elements = categories|merge(tags) %}

&lt;ul class="pills"&gt;
    &lt;li&gt;&lt;a href="javascript:void(0);" class="btn btn-secondary filter" data-filter="all"&gt;All&lt;/a&gt;&lt;/li&gt;

    {% for element in elements | supersort('natcasesort') %}
        &lt;li&gt;&lt;a href="javscript:void(0)" class="btn btn-secondary filter" data-filter=".category-{{ element.title|kebab }}"&gt;{{ element.title|capitalize }}&lt;/a&gt;&lt;/li&gt;
    {% endfor %}
&lt;/ul&gt;
</code></pre>

<tags>
Show tags in tag group only being used on live entries
# Show tags in tag group only being used on live entries

(Asked by: username_0 on 2015-10-26)

Looking to loop through tags from entries but limit to only show tags that are being used on entries. Right now this just loops through any and all created tags.
I tried limit to null but have had no luck getting that to work.
{% set categories = craft.categories.group('storiesCategories').find %}
{% set tags = craft.tags.group('storiesTagGroup').find %}
{% set elements = categories|merge(tags) %}


    All

    {% for element in elements | supersort('natcasesort') %}
        {{ element.title|capitalize }}
    {% endfor %}

**Tags:** tags

---

## 1 answers

### Answer by username_1 on 2015-10-26. Score: 2 | Accepted answer

Your mention tags, but it seems like you're merging Categories and Tags together and trying to loop through the results.
If you leave Categories out of the equation it's as simple as this.
If you want Categories and Tags, you'd repeat that process twice and merge the results.
Note that using |merge on full-fledged arrays of objects is sketchy, though, since it's difficult for PHP to know how to compare the objects for equality.  You'll be much better off merging on something primitive, like an array of element IDs.
Something like:
{% set categoryIds = craft.categories.group('storiesCategories').ids() %}
{% set tagIds = craft.tags.group('storiesTagGroup').ids() %}
{% set elementIds = categoryIds|merge(tagIds) %}


---

