Tags menu not displaying tags from site page

Hello, I am having trouble with a menu using tags. I want to filter all my website images based on tags and this is working the problem I have is that the tags of the images are queried from the site.yml and on my homepage I have a menu with these tags but if I delete a Tag from the site this still shows up on my homepage menu because this menu is showing all the tags on the images instead of showing only the tags on the site.

I added to my site.yml a tags field:

            label: Tags
            type: tags

And then on my images yml I added this:

    label: Filters
    type: multiselect
    options: query
    query: site.tags.split

Then on my home template I have the following:

<div class="tags">
  <?php foreach ($tags as $tag): ?>
    <a href="<?= url('projects', ['params' => ['tag' => $tag]]) ?>">
      <?= html($tag)?>
    <?php endforeach ?>

and on my home controller:


return function ($site, $page) {
    $projects = page('projects')->children()->listed();
    $images   =  $projects->images();
    $tags     = $images->pluck('tags', ',', true);

    if ($tag = param('tag')) {
        $images = $images->filterBy('tags', $tag, ',');

    return compact('projects', 'images', 'tags', 'tag');

I think the problem is on my controller or template because I am pushing the tags from the images where I should actually be pushing the tags from the site and I tried to change it but without success. can someone please point me in the right direction?

What I need is if I delete a tag on the site panel this tag shouldn’t be visible on the homepage menu even if an image is still using this tag because somehow if I delete something on the site the multiselect doesn’t delete this option if it was already in use.

Yes, the problem is that your image tags are not automatically updated to reflect it when tags are removed from your site tags.

On way to go about this would be to programmatically update all tags of all images when a change happens in the site tags. This could be achieved via a hook but might result in issues when you have many images. It would therefore make sense to clean up the image meta data every once in a while via a CLI script.

An easier to implement approach would be to actually filter the tags you fetch from the images by the tags that are actually allowed.

$tags = $images->pluck('tags', ',', true);
$siteTags = $site->tags()->split(',');

// use only those tags that are actually present in $siteTags
$tags = array_intersect($siteTags, $tags);

Thank you so much for your quick answer it works great with the sitetags