Answers.Body: <p>Maybe not the most elegant, but something like this should work:</p>
  
  <pre><code>{% set entries = craft.entries.section('faqs') %}
  {% set usedCategoryIds = [] %}
  
  {% for entry in entries %}
      {% for category in entry.faqCategory %}
          {% if category.id not in usedCategoryIds %}
              &lt;li&gt;&lt;a href="#{{ category.title }}" class="filter" data-filter=".{{ category.title }}"&gt;{{ category.title }}&lt;ins&gt;&amp;nbsp;&lt;/ins&gt;&lt;/a&gt;&lt;/li&gt;
  
              {% set usedCategoryIds = usedCategoryIds|merge([category.id]) %}
          {% endif %}
      {% endfor %}
  {% endfor %}
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-04-19T06:25:46.317Z
Answers.Text: And it does! That solved the issue.
Answers.UserDisplayName: Robbie Post
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-04-18T19:18:03.473Z
Answers.LastActivityDate: 2017-04-18T19:18:03.473Z
Answers.UserDisplayName: Brad Bell
Body: <p>I have a set of FAQ entries. Each entry has one or more categories attached. To be able to filter entries related to a category I need a list with unique categories. </p>
  
  <p>Using my solution I'm getting all (some double) categories.</p>
  
  <pre><code>   {% set entries = craft.entries.section('faqs') %}
     {% for entry in entries %}
          {% for category in entry.faqCategory %}
               &lt;li&gt;&lt;a href="#{{ category.title }}" class="filter" data-filter=".{{ category.title }}"&gt;{{ category.title }}&lt;ins&gt;&amp;nbsp;&lt;/ins&gt;&lt;/a&gt;&lt;/li&gt;
          {% endfor %}
      {% endfor %}
  </code></pre>
  
Tags: <categories><category>
Title: How to get the unique categories from a list
ThreadText: # How to get the unique categories from a list
  
  (Asked by: username_0 on 2017-04-18)
  
  I have a set of FAQ entries. Each entry has one or more categories attached. To be able to filter entries related to a category I need a list with unique categories.
  
  Using my solution I'm getting all (some double) categories.
  
  ```
     {% set entries = craft.entries.section('faqs') %}
     {% for entry in entries %}
          {% for category in entry.faqCategory %}
               <li><a href="#{{ category.title }}" class="filter" data-filter=".{{ category.title }}">{{ category.title }}<ins>&nbsp;</ins></a></li>
          {% endfor %}
      {% endfor %}
  
  ```
  
  **Tags:** categories, category
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2017-04-18. Score: 1 | Accepted answer
  
  Maybe not the most elegant, but something like this should work:
  
  ```
  {% set entries = craft.entries.section('faqs') %}
  {% set usedCategoryIds = [] %}
  
  {% for entry in entries %}
      {% for category in entry.faqCategory %}
          {% if category.id not in usedCategoryIds %}
              <li><a href="#{{ category.title }}" class="filter" data-filter=".{{ category.title }}">{{ category.title }}<ins>&nbsp;</ins></a></li>
  
              {% set usedCategoryIds = usedCategoryIds|merge([category.id]) %}
          {% endif %}
      {% endfor %}
  {% endfor %}
  
  ```
  
  > **Comments:**
  > **username_0**: And it does! That solved the issue.  
  
  ---
  
  