Filtering by selecting multiple tags

Hello !
First, thank you for all the help I found on this forum.

I have two lists of tags to filter the subpages. It works perfectly fine when I select one Tag at a time in each list but I would like to be able to select two or three tags in each list to filter the results. I’ve tried a few things but I can’t make it work.

Here’s my controller

<?php

return function ($kirby, $pages, $page) {

  $projetsAll = $page->children()->filterBy('template', 'projet');
  $projets = $projetsAll->filterBy('shopItem', false);
   
  if($type = param('type')) {
    $type = urldecode(param('type'));    
    $projets = $projets->filterBy('typ', $type, ',');
  }
  if($topic = param('topic')) {
    $topic = urldecode(param('topic'));    
    $projets = $projets->filterBy('top', $topic, ',');
  }

  $types = $projets->pluck('typ', ',', true); 
  $topics = $projets->pluck('top', ',', true);

return compact('type', 'types', 'topic', 'topics', 'projets');

};

And the snipet with the tag menu for the “topic” list

 <?php foreach($topics as $to): ?>
    <?php if($to == urldecode(param('topic'))): ?>
    <a <?php if( urldecode(param('topic')) === $topic ) { echo('class="active"'); } ?> href="<?= url($page->url(), ['params' => ['type' => urlencode($type)]]) ?>"><?= html($to) ?></a><span class="em-space"></span>
    <?php else : ?>
    <a class="btnFilter <?= Str::slug($to) ?>"
        href="<?= url($page->url(), ['params' => [ 'topic' => urlencode($to), 'type' => urlencode($type)]]) ?>"><?= html($to) ?></a><span class="em-space"></span>
    <?php endif;?>
    <?php endforeach ?>

If anyone has a lead on this It would be very helpful !

Links are not the ideal way to deal with this. You can either turn this into a form (checkboxes, multiselect) or use a JavaScript library for filtering.

Thank you for your answer, I will try with multiselect. I need to be able to create tags from the panel so I’ll try to populate the multiselect field with a tag field.