<p>I don't think this is possible witout the use of a plugin. The craft.entries tag works on an entry basis. The slug is saved in the table that houses the localized data for an element, craft_elements_i18n. When you request an entry, (in theory) the craft_entries table is joined with the craft_elements table (based on id), which is then joined with the craft_elements_i18n table (based on locale). There's no way you could join in data from several different locales this way.</p>

<p>What you have to do is query the craft_elements_i18n directly, and return all rows based on the entry id (elementId in that table is the entry id), and then you'd get locale, slug, and url. This table isn't exposed in any way to the templates, so you'd need to do it with a small plugin. It will still be one query to do this, though. </p>

<p>I think maybe this is more work than what it's worth, unless you have loads of locales, the difference in performance will be very, very small. Also, you could cache this in your templates, which would make it even less of an issue.</p>

CC BY-SA 3.0
2015-02-20T16:12:04.883Z
2015-02-20T16:12:04.883Z
André Elvan
<p>I've been looking at <a href="https://craftcms.stackexchange.com/questions/44/how-can-i-build-a-language-switcher">How can I build a language switcher?</a> but I don't to hit the DB for each entry in the loop, just to get the entry's localised slug.</p>

<p>However I can't see a way to get an entry by ID with anything other than the current or a specific locale.</p>

<p>So assuming I'm on a template where we have an entry defined, this returns 1 entry in current locale:</p>

<pre><code>craft.entries.id(entry.id);
</code></pre>

<p>And this returns 1 entry in a different locale:</p>

<pre><code>craft.entries.id(entry.id).locale('es');
</code></pre>

<p>How can I get entries for ALL locales so I can do one DB query rather than one for every locale that's enabled on the site?</p>

<localization>
Retrieving an entry by ID in ALL locales
# Retrieving an entry by ID in ALL locales

(Asked by: username_0 on 2015-02-19)

I've been looking at How can I build a language switcher? but I don't to hit the DB for each entry in the loop, just to get the entry's localised slug.
However I can't see a way to get an entry by ID with anything other than the current or a specific locale.
So assuming I'm on a template where we have an entry defined, this returns 1 entry in current locale:
craft.entries.id(entry.id);

And this returns 1 entry in a different locale:
craft.entries.id(entry.id).locale('es');

How can I get entries for ALL locales so I can do one DB query rather than one for every locale that's enabled on the site?

**Tags:** localization

---

## 1 answers

### Answer by username_1 on 2015-02-20. Score: 2 | Accepted answer

I don't think this is possible witout the use of a plugin. The craft.entries tag works on an entry basis. The slug is saved in the table that houses the localized data for an element, craft\_elements\_i18n. When you request an entry, (in theory) the craft\_entries table is joined with the craft\_elements table (based on id), which is then joined with the craft\_elements\_i18n table (based on locale). There's no way you could join in data from several different locales this way.

What you have to do is query the craft\_elements\_i18n directly, and return all rows based on the entry id (elementId in that table is the entry id), and then you'd get locale, slug, and url. This table isn't exposed in any way to the templates, so you'd need to do it with a small plugin. It will still be one query to do this, though.

I think maybe this is more work than what it's worth, unless you have loads of locales, the difference in performance will be very, very small. Also, you could cache this in your templates, which would make it even less of an issue.


---

