I want my <ul> to show a single tag representing all "active" entries ( "active" using a custom lightswitch field in the entry: fellowStatus.

Each tag is a year (e.g. 2014, 2010, etc)

E.g. if there are no "active" entries with the tag 2017, it should not display.

The code block below spits out only tags where entries are "active" BUT... It spits out duplicates of each tag depending on how many entries are using it. (e.g. It displays 8 instances of 2015 instead of 1)

{% for entry in craft.entries.section('fellows').limit(null) %}

  {% set tags = craft.tags.relatedTo(entry).limit(1).find() %}
  {% set active = entry.fellowStatus %}

    {% if entry.fellowStatus == 0 %}

      {% for tag in tags %}
            <a href="{{ tag }}">{{ tag.title }}</a>
      {% endfor %}

    {% endif %}

{% endfor %}
  • Do you want to show all tags related to your entries or do you want to display all tags for each entry? Apr 27 '18 at 4:36
  • I want to show all tags that are in use. E.g. If 2015 has an entry, show. If 2001 doesn't have an entry, don't show. If 2017 has an entry, but fellowStatus light switch is off, don't show. Apr 30 '18 at 18:15

First: grab all entries that match your criteria

Second: grab all Tags related to your entries


$entryIds = Entry::find()
$tagsRelatedToEntries = Tag::find()


{% set entryIds = craft.entries
{% set tags = craft.tags.relatedTo(entryIds).all() %}

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.