1

I have craft pro and have one tagGroup called Tags Then I created a Tag field called newsTag like this: Tags field setup

When I add a tag for german, the tag is also created in the database for dutch and english, so when I get a list of used tags like this:

{% set tagsEntries = craft.entries
    .section('news')
    .limit(null)
    .all() %}

{% for atag in craft.tags.relatedTo(tagsEntries) %}
    <li {% if tag == atag.title %} class="is-active" {% endif %}><a href="{{ newsEntry.url }}/{{ atag.slug }}">{{ atag.title }}</a></li>
{% endfor %}

Now I get all tags used in all sites. when I use it like this:

{% set tags = craft.tags.relatedTo({
      sourceElement: tagsEntries,
      sourceLocale: craft.site
    }) %}

Then I still get all tags, because when I look at the database the tag for German is also created for Dutch and English:

In the content table:

content table

When I remove the entry for site 1 and 3 (the dutch and english site) the it works, but will be added again on entry save...

Is it somehow possible to only save a tag for one site? That way I can get all the tags only used in that site and not all.

ps, this only happens with tags in entries that are used/enabled for 2 or more sites.

Thanks for the help,

Dimitri

1

currently disabling multi site for tag is not supported

unless you were to fork Craft and change the isLocalized() return value from true to false

https://github.com/craftcms/cms/issues/3483#issuecomment-440782270

so tag itself is always created for all languages but you need another thing.

you need adding tag to entry per site basis so you have to check tag field -> advanced setting -> Manage relations on a per-site basis -it seems you enabled this already-.

now if there is two site and tag1 is added or selected for site1 entry but tag1 is not selected for that entry on site2, if you change source Locale to site2 id on your code, tag1 is not showing on results. - still tag1 is available on site1 and site2 but is not showing up on result because you enabled manage tag on per site basis and tag1 is not attached to site2 entry -

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.