<p>I think this is actually two problems you have, Adam.</p>

<p>Isn't <code>dateCreated</code> – which you are now using with the code you provided – something different to "recently used", your actual plan to filter your tags by? I don't know it there's a built in way to get the therefore necessary info, the "entry-tag-relation creation date".</p>

<p>You could try <code>dateModified</code> on the tag model, but I'm not sure if this works (maybe worth a feature request though? → <a href="http://buildwithcraft.com/help" rel="nofollow">support@buildwithcraft.com</a> or <a href="https://plus.google.com/u/0/communities/106505340287442511226/stream/3ff4ba0f-25e6-4f6f-ad4b-04da3a7e81c9" rel="nofollow">"Craft: Feedback and Ideas" section on g+</a>).</p>

CC BY-SA 3.0
2014-07-31T12:01:06.390Z
You're right carlcs: dateCreated is not exactly what I would want. What I really want is "date last used or created, whichever is newer." Thanks for the feature request link. I'll use it.
Adam Snetman
CC BY-SA 3.0
2014-07-31T12:05:23.270Z
Did you try `dateModified desc`? That'd only work if a tag is updated in the DB after each new relation registered on it. Maybe worth a try..
carlcs
CC BY-SA 3.0
2014-07-31T12:13:53.663Z
I thought of that and did try it, but from what I was getting back, it didn't appear that Craft considers applying a tag as a modification.
Adam Snetman
CC BY-SA 3.0
2014-07-31T08:53:49.833Z
2014-07-31T09:05:25.023Z
2014-07-31T09:05:25.023Z
carlcs
<p>Brandon at P&amp;T was able to fill in the piece I was missing. He said:</p>

<p>To only get tags that were related from a specific locale, you just need to specify that in your <a href="http://buildwithcraft.com/docs/relations#the-relatedTo-param" rel="nofollow"><code>relatedTo</code></a> param:</p>

<pre><code>    {% set tags = craft.tags.relatedTo({
      sourceElement: entries,
      sourceLocale: craft.locale
    }) %}
</code></pre>

<p>With the addition of <code>order('dateCreated desc').limit(10)</code> to put some additional constraints on what I was getting back, this solved it for me. </p>

CC BY-SA 3.0
2014-07-30T17:59:41.837Z
2014-07-31T08:13:16.370Z
2014-07-31T08:13:16.370Z
Adam Snetman
<p>I'm having trouble outputting a list of tags that only includes tags from the current locale.</p>

<p>Here's the setup:</p>

<ol>
<li>I have a site with two locales: english and spanish</li>
<li>I have a section with handle newsAndEvents</li>
<li>I have a tag field with handle newsTags on entries in that section that is set to translatable to allow my clients to assign locale-specific tags to the entries</li>
<li>I have an entry in that section created with a published version for each of my locales. In the english version, I've added a tag "Turtles" to the entry. In the spanish version, I've added a tag "Tortugas" to the entry.</li>
<li><p>On the landing page of my news section, I am displaying a list of recent tags in a sidebar. Here's the code I'm using to do it:</p>

<pre><code>{# grab the entries in the specific locale #}
{% set entries = craft.entries.find({section: 'newsAndEvents', locale: craft.locale}) %}

{# Grab the related tags for those entries #}
{% set tags = craft.tags.relatedTo(entries) %}

{# Build the list #}
{% if tags | length %}
  &lt;ul class="tag-list"&gt;
  {% for tag in tags %}
    &lt;li&gt;&lt;a class="tag" href="#"&gt;{{ tag.name }}&lt;/a&gt;&lt;/li&gt;
  {% endfor %}
  &lt;/ul&gt;
{% endif %}
</code></pre></li>
<li>The problem is, when I'm looking at the english version of my landing page, I get both "Tortugas" and "Turtles" in the list output by the code above. What I want is to only see the tags on english versions entries on the english landing page; and the tags on spanish versions of entries on the spanish landing page.</li>
</ol>

<p>Some additional info:</p>

<ul>
<li><p>If an entry has only one published version, english for example, any tags I assign to that version do not appear on the spanish landing page, as would be expected.</p></li>
<li><p>On my entry detail pages, I'm using similar code to generate a list of tags assigned to the current entry, and the output is what I expect: english versions only show tags assigned to english versions, not to both english and spanish like on the landing page.</p></li>
</ul>

<p>What am I missing?</p>

<localization><tags>
Show a list of recently used tags only from the current locale
# Show a list of recently used tags only from the current locale

(Asked by: username_0 on 2014-07-30)

I'm having trouble outputting a list of tags that only includes tags from the current locale.
Here's the setup:

I have a site with two locales: english and spanish
I have a section with handle newsAndEvents
I have a tag field with handle newsTags on entries in that section that is set to translatable to allow my clients to assign locale-specific tags to the entries
I have an entry in that section created with a published version for each of my locales. In the english version, I've added a tag "Turtles" to the entry. In the spanish version, I've added a tag "Tortugas" to the entry.
On the landing page of my news section, I am displaying a list of recent tags in a sidebar. Here's the code I'm using to do it:
{# grab the entries in the specific locale #}
{% set entries = craft.entries.find({section: 'newsAndEvents', locale: craft.locale}) %}

{# Grab the related tags for those entries #}
{% set tags = craft.tags.relatedTo(entries) %}

{# Build the list #}
{% if tags | length %}
  
  {% for tag in tags %}
    {{ tag.name }}
  {% endfor %}
  
{% endif %}

The problem is, when I'm looking at the english version of my landing page, I get both "Tortugas" and "Turtles" in the list output by the code above. What I want is to only see the tags on english versions entries on the english landing page; and the tags on spanish versions of entries on the spanish landing page.

Some additional info:

If an entry has only one published version, english for example, any tags I assign to that version do not appear on the spanish landing page, as would be expected.
On my entry detail pages, I'm using similar code to generate a list of tags assigned to the current entry, and the output is what I expect: english versions only show tags assigned to english versions, not to both english and spanish like on the landing page.

What am I missing?

**Tags:** localization, tags

---

## 2 answers

### Answer by username_0 on 2014-07-30. Score: 6 | Accepted answer

Brandon at P&T was able to fill in the piece I was missing. He said:
To only get tags that were related from a specific locale, you just need to specify that in your relatedTo param:
    {% set tags = craft.tags.relatedTo({
      sourceElement: entries,
      sourceLocale: craft.locale
    }) %}

With the addition of order('dateCreated desc').limit(10) to put some additional constraints on what I was getting back, this solved it for me.


---

### Answer by username_1 on 2014-07-31. Score: 0

I think this is actually two problems you have, Adam.

Isn't `dateCreated` – which you are now using with the code you provided – something different to "recently used", your actual plan to filter your tags by? I don't know it there's a built in way to get the therefore necessary info, the "entry-tag-relation creation date".

You could try `dateModified` on the tag model, but I'm not sure if this works (maybe worth a feature request though? → [support@buildwithcraft.com](http://buildwithcraft.com/help) or ["Craft: Feedback and Ideas" section on g+](https://plus.google.com/u/0/communities/106505340287442511226/stream/3ff4ba0f-25e6-4f6f-ad4b-04da3a7e81c9)).

> **Comments:**
> **username_0**: You're right carlcs: dateCreated is not exactly what I would want. What I really want is "date last used or created, whichever is newer." Thanks for the feature request link. I'll use it.  
> **username_1**: Did you try `dateModified desc`? That'd only work if a tag is updated in the DB after each new relation registered on it. Maybe worth a try..  
> **username_0**: I thought of that and did try it, but from what I was getting back, it didn't appear that Craft considers applying a tag as a modification.  

---

