# List of Primary Tags

**URL:** <https://forum.ghost.org/t/list-of-primary-tags/28079>\
**Category:** Themes\
**Created:** [January 23, 2022, 8:17pm UTC](https://forum.ghost.org/t/list-of-primary-tags/28079 "2022-01-23T20:17:07Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jesus\_Esquivel\_Roman](https://sea1.discourse-cdn.com/flex015/user_avatar/forum.ghost.org/jesus_esquivel_roman/32/16110_2.png) [@Jesus\_Esquivel\_Roman](https://forum.ghost.org/u/Jesus_Esquivel_Roman)\
**Post date:** [January 23, 2022, 8:17pm UTC](https://forum.ghost.org/t/list-of-primary-tags/28079/1 "2022-01-23T20:17:07Z")

</div>

Hi all,

I basically want to get a list of primary tags and a list of regular tasks. I can return a list of all tags but I am unsure on how to filter it to just return the primary tags (and do the same to just return the regular ones).

This is how I return all the tags, but how can I filter to just return the primary tags? Thanks!

```auto
    {{#get "tags" as |tag|}}
    <div class="dropdown">
        <ul class="dropdown-menu">
            {{#foreach tag}}
            <li><a class="dropdown-item tag" href="{{url}}">{{name}}</a></li>
            {{/foreach}}
        </ul>
    </div>
    {{/get}}

```

---

<div class="post-metadata">

**Author:** ![brightthemes](https://sea1.discourse-cdn.com/flex015/user_avatar/forum.ghost.org/brightthemes/32/25099_2.png) [@brightthemes](https://forum.ghost.org/u/brightthemes)\
**Post date:** [January 26, 2022, 7:43am UTC](https://forum.ghost.org/t/list-of-primary-tags/28079/2 "2022-01-26T07:43:24Z")

</div>

Primary tags only exist in the context of a post (the same tag could be primary\_tag in one post and a normal one in another).  
The tag object doesn’t have a property to identify it as primary:

> **[Tag Context: Ghost Themes - Documentation](https://ghost.org/docs/themes/contexts/tag/#tag-object)**
>
> The tag context is used in Ghost themes to render lists of posts with the same tag in a publication. Learn more about contexts and building a custom theme!

---

<div class="post-metadata">

**Author:** ![ahmadajmi](https://sea1.discourse-cdn.com/flex015/user_avatar/forum.ghost.org/ahmadajmi/32/23173_2.png) [@ahmadajmi](https://forum.ghost.org/u/ahmadajmi)\
**Post date:** [January 26, 2022, 3:23pm UTC](https://forum.ghost.org/t/list-of-primary-tags/28079/3 "2022-01-26T15:23:11Z")

</div>

This is a workaround.

1. Loop through posts
2. Loop through tags for each post. Limit the tags to one, which will be the primary tag.

```auto
{{#get 'posts' include='tags'}}
  {{#foreach posts}}
    {{#foreach tags limit='1'}}
    <li class='item' data-slug='{{slug}}'>
      <a href='{{ url }}'>{{ name }}</a>
    </li>
    {{/foreach}}
  {{/foreach}}
{{/get}}

```

1. All the primary tags will be now visible but with duplication. With some JS, you can clean the duplicated ones.

```auto
<script>
$(document).ready(function() {
  var found = {};
  $('.item').each(function() {
    var $this = $(this);
    if(found[$this.attr('data-slug')]) {
      $this.remove();
    } else {
      found[$this.attr('data-slug')] = true;
    }
  });
});
</script>

```

Make sure jQuery is loaded before that JS code. _JS code credit: [https://mijokristo.com/remove-duplicate-elements-from-list-by-value-with-jquery/](https://mijokristo.com/remove-duplicate-elements-from-list-by-value-with-jquery/)_

_Update (None jQuery Code):_

```auto
<script>
  var finalList = { },
      elements = document.querySelectorAll('.item');

  elements.forEach( element => {
    if (finalList[element.dataset.slug]) {
      element.style.display= 'none';
    } else {
      finalList[element.dataset.slug] = true;
    }
  });
</script>

```

---

<div class="post-metadata">

**Author:** ![Jesus\_Esquivel\_Roman](https://sea1.discourse-cdn.com/flex015/user_avatar/forum.ghost.org/jesus_esquivel_roman/32/16110_2.png) [@Jesus\_Esquivel\_Roman](https://forum.ghost.org/u/Jesus_Esquivel_Roman)\
**Post date:** [January 29, 2022, 4:41pm UTC](https://forum.ghost.org/t/list-of-primary-tags/28079/4 "2022-01-29T16:41:07Z")

</div>

Amazing, it worked. Thank you so much! I really like your Ghost Tips & Tricks series, great work. Please share any blogs, tutorials or videos that you may have I would like to learn more 😊

---

<div class="post-metadata">

**Author:** ![ahmadajmi](https://sea1.discourse-cdn.com/flex015/user_avatar/forum.ghost.org/ahmadajmi/32/23173_2.png) [@ahmadajmi](https://forum.ghost.org/u/ahmadajmi)\
**Post date:** [February 3, 2022, 10:43am UTC](https://forum.ghost.org/t/list-of-primary-tags/28079/5 "2022-02-03T10:43:14Z")

</div>

Pleasure, Jesus! I regularly publish new content on Aspire Themes [blog](https://aspirethemes.com/blog/) and the [tips](https://aspirethemes.com/tips) page. Also, @Tiago shares some great content at [https://www.thestackjunction.com/](https://www.thestackjunction.com/)

---

<div class="post-metadata">

**Author:** ![Tiago](https://sea1.discourse-cdn.com/flex015/user_avatar/forum.ghost.org/tiago/32/15101_2.png) [@Tiago](https://forum.ghost.org/u/Tiago)\
**Post date:** [February 3, 2022, 11:04am UTC](https://forum.ghost.org/t/list-of-primary-tags/28079/6 "2022-02-03T11:04:32Z")

</div>

Thanks for the mention @ahmadajmi 😀

I also share some stuff about Ghost on YT if you’re into it: [https://www.youtube.com/channel/UCRwkVyZXSWS1VIgnWd3j\_LA](https://www.youtube.com/channel/UCRwkVyZXSWS1VIgnWd3j_LA)
