Filtering by multiple Tags

Hello, I am trying to put multiple tags on the page, filtering items by each other or sometimes together…
the url like → home/category:works + timeline:2022
But using these codes(below an image), I keep getting this error message…

on controller.php

  $workcategory = param('category');
  $worktimeline = param('timeline');
  
  $artworks = page('home/works')->children()->listed()
      ->when($workcategory, function ($workcategory) {
          return $this->filterBy('category', $workcategory);
      })
      ->when($worktimeline, function ($worktimeline) {
          return $this->filterBy('timeline', $worktimeline);
      });
     
  $categories = $artworks->pluck('category', ',', true);
  $timelines = $artworks->pluck('timeline', ',', true);

<?php foreach($categories as $c): ?>
    <li>
      <a  href="<?= url('home', ['params' => array_merge(params(),['category' => $categories])]) ?>">
        <?= html($c) ?>
      </a>
    </li>
    <?php endforeach ?>

Could you let me know how to filter by multiple tags in Kirby 3.7.5?
Thank you:)

You are passing your array of categories as parameter instead of the single category, so use $c instead of $categories.

Thanks, now it works!
However, when I click the tags, except the clicked tags, the other tags are gone.
(URL is like this : home/timeline:2021/category:installations)
Do you know how can I keep the other tags for the next move?

That’s because you define your $categories/$timelines after filtering. You have to get them first, then apply the filter.

$artworks   = page('home/works')->children()->listed();
$categories = $artworks->pluck('category', ',', true);
$timelines  = $artworks->pluck('timeline', ',', true);
$artworks   = $artworks
      ->when($workcategory, function ($workcategory) {
          return $this->filterBy('category', $workcategory);
      })
      ->when($worktimeline, function ($worktimeline) {
          return $this->filterBy('timeline', $worktimeline);
      });
1 Like

Thank you so much:)