Show all tags in template but without repeating tags

Hello Everyone :slight_smile:
I’m trying to create a menu of all the tags of the works in the page so the user could filter works by the tags.

Since some works have the same tags it shows some tags multiple times (depends on how many works have the same tag). is there a way to show all the tags without repeating them?

This is how I show them in the template right now:

    <div class='all-tags'>
        <?php foreach ($page->children()->listed() as $work): ?>
                <?php foreach ($work->tags()->split() as $tag): ?>
                    <div class='tag' ><?= $tag ?></div>
                <?php endforeach ?>
        <?php endforeach ?>
    </div>

Would appreciate any help :slight_smile:

You can use the pluck() method to pluck all tags from all pages:

<?php
$tags = $page->children()->listed()->pluck('tags', ',', true);
foreach ($tags as $tag): ?>
  <div class='tag' ><?= $tag ?></div>
<?php endforeach ?>

The last parameter tells the pluck method to only return unique tags.

It works perfectly!
Thank you so much