<p>You can use the relatedTo param on <code>craft.tags</code> like you can with any Element inside Craft.</p>

<p>All Elements inside Craft can be related to one another. There is a <code>.relatedTo</code> <a href="https://craftcms.com/docs/templating/craft.tags#relatedTo" rel="nofollow">parameter</a> available on all of the query elements like <code>craft.entries</code> and <code>craft.tags</code>.  </p>

<p>You will need to pass a category object into this relatedTo parameter. I have included the group param below but this can be omitted if you want to query all of your tags.</p>

<p><code>{% set tags = craft.tags.group( 'groupName' ).relatedTo( category ) %}</code></p>

<p>More info on using Relations in Craft: <a href="https://craftcms.com/docs/relations" rel="nofollow">https://craftcms.com/docs/relations</a></p>

<hr>

<p><strong>UPDATE</strong></p>

<p>The <code>relatedTo</code> param takes one of the following:</p>

<ul>
<li>An AssetFileModel, CategoryModel, EntryModel, UserModel, or TagModel
object </li>
<li>An element’s ID </li>
<li>An array of element objects and/or IDs</li>
</ul>

<p>To get a CategoryModel using a slug inside your template you can use:</p>

<p><code>{% set category = craft.categories.slug( 'theslug' ).first() %}</code></p>

<p>This will set <code>category</code> to a CategoryModel which you can then use inside the <code>.relatedTo</code> param in the above example.</p>

<hr>

<p><strong>UPDATE 2</strong></p>

<p>If you've set category to have their own URL's then <code>category</code> inside the template you've set to use is a CategoryModel.</p>

<p>You then set <code>entries</code> to all entries related to the category. Finally, use these entries to get all related tags.</p>

<pre><code>{% set entries = craft.entries.relatedTo( category ).find() %}
{% set tags = craft.tags.relatedTo( entries ).find() %}
</code></pre>

CC BY-SA 3.0
2016-05-31T12:18:15.070Z
Thanks. How do I set the actual category?
Erik
CC BY-SA 3.0
2016-05-31T12:37:04.120Z
That depends on where you are setting these tags to be displayed. You can get categories the same way you get entries using `craft.categories`. If you have set categories to have their own URLs then `category` will be the current category you're viewing.
Luke Pearce
CC BY-SA 3.0
2016-05-31T12:57:06.740Z
Ok, thanks for the help! I just started using Craft, so I'm still trying to wrap my ahead around some of the concepts.
Erik
CC BY-SA 3.0
2016-05-31T17:15:34.933Z
Ok, I updated my original question with an edit. I'm still not getting this to work, and maybe I was misunderstood.
Erik
CC BY-SA 3.0
2016-05-31T17:46:45.160Z
So I tried to do that and nothing displayed. I used `{% set category = craft.categories.slug('slug') %}` and `{% set tags = craft.tags.relatedTo( category ) %}`. I guess I will just mess around with it a bit more.
Erik
CC BY-SA 3.0
2016-05-31T17:49:26.080Z
You need to use `.first()` when getting the category. Are you setting these tags on a category?
Luke Pearce
CC BY-SA 3.0
2016-05-31T18:01:38.670Z
Here is how I am trying to use this. This will be on a category page. So, I will know what category it is. From there, I will list all the entries in the category. At the bottom, I want a tag cloud type thing to showcase all the tags related to this category used in the entries listed above it. Does that make sense?
Erik
CC BY-SA 3.0
2016-05-31T18:04:58.803Z
So your tags are set on the entries? This means you need to use the entries to get the related tags and these entries will all be from one category.
Luke Pearce
CC BY-SA 3.0
2016-05-31T18:21:48.917Z
Kick ass, update 2 was exactly what I was looking for. Thanks!
Erik
CC BY-SA 3.0
2016-05-28T11:18:55.137Z
2016-05-31T18:11:18.107Z
2016-05-31T18:11:18.107Z
Luke Pearce
<p>Is it possible to show all tags that are related to a category? I can't find anything on it.</p>

<p>Thanks.</p>

<p><strong>Edit:</strong></p>

<p><em>What I am looking for is this:</em></p>

<p>I know a category slug or name. I want to get all tags associated with entries in that category.</p>

<p>I can't seem to get this to work using the relatedTo param.</p>

CC BY-SA 3.0
2016-05-28T09:28:56.573Z
Is your tag custom field inside the category or an entry?
Matt P
<categories><relations><tags>
Show all tags related to a category?
# Show all tags related to a category?

(Asked by: username_0 on 2016-05-27)

Is it possible to show all tags that are related to a category? I can't find anything on it.

Thanks.

**Edit:**

*What I am looking for is this:*

I know a category slug or name. I want to get all tags associated with entries in that category.

I can't seem to get this to work using the relatedTo param.

**Tags:** categories, relations, tags
> **Comments:**
> **username_1**: Is your tag custom field inside the category or an entry?  

---

## 1 answers

### Answer by username_2 on 2016-05-28. Score: 4 | Accepted answer

You can use the relatedTo param on craft.tags like you can with any Element inside Craft.
All Elements inside Craft can be related to one another. There is a .relatedTo parameter available on all of the query elements like craft.entries and craft.tags.  
You will need to pass a category object into this relatedTo parameter. I have included the group param below but this can be omitted if you want to query all of your tags.
{% set tags = craft.tags.group( 'groupName' ).relatedTo( category ) %}
More info on using Relations in Craft: https://craftcms.com/docs/relations

UPDATE
The relatedTo param takes one of the following:

An AssetFileModel, CategoryModel, EntryModel, UserModel, or TagModel
object 
An element’s ID 
An array of element objects and/or IDs

To get a CategoryModel using a slug inside your template you can use:
{% set category = craft.categories.slug( 'theslug' ).first() %}
This will set category to a CategoryModel which you can then use inside the .relatedTo param in the above example.

UPDATE 2
If you've set category to have their own URL's then category inside the template you've set to use is a CategoryModel.
You then set entries to all entries related to the category. Finally, use these entries to get all related tags.
{% set entries = craft.entries.relatedTo( category ).find() %}
{% set tags = craft.tags.relatedTo( entries ).find() %}

> **Comments:**
> **username_0**: Thanks. How do I set the actual category?  
> **username_2**: That depends on where you are setting these tags to be displayed. You can get categories the same way you get entries using `craft.categories`. If you have set categories to have their own URLs then `category` will be the current category you're viewing.  
> **username_0**: Ok, thanks for the help! I just started using Craft, so I'm still trying to wrap my ahead around some of the concepts.  
> **username_0**: Ok, I updated my original question with an edit. I'm still not getting this to work, and maybe I was misunderstood.  
> **username_0**: So I tried to do that and nothing displayed. I used `{% set category = craft.categories.slug('slug') %}` and `{% set tags = craft.tags.relatedTo( category ) %}`. I guess I will just mess around with it a bit more.  
> **username_2**: You need to use `.first()` when getting the category. Are you setting these tags on a category?  
> **username_0**: Here is how I am trying to use this. This will be on a category page. So, I will know what category it is. From there, I will list all the entries in the category. At the bottom, I want a tag cloud type thing to showcase all the tags related to this category used in the entries listed above it. Does that make sense?  
> **username_2**: So your tags are set on the entries? This means you need to use the entries to get the related tags and these entries will all be from one category.  
> **username_0**: Kick ass, update 2 was exactly what I was looking for. Thanks!  

---

