Show pages by filtering multiple tags?


#1

Hi all,
how to display pages with multiple tags.

foreach(page('sites')->children()->visible()->filterBy('tags', 'tag1,tag2,tag4' ',')->limit(3) as $project):

The result shoule be: 3 items, with tags from different pages.
example:
Page1: tag1, tag5, tag4
Page2: tag1, tag2, tag3
Page3: tag2, tag5, tag4

result: page1, page2 , page3

How to realise that?


Filtering blog post by two independent tags
#2

You could use a custom filter like this one for multiple file extensions:


#3

Hi,

i dont’t want to filter files. I want to show different page items via tags.


#4

I know, it was just an example that you can adapt to filter pages instead of files


#5

Hi,

it works, thanks alot.


#6

hey, peterp, how did you resolve your question?


#7

up!
@peterp please share your solution


#8

You can use a filter operator:

$filterTags = ['tag1', 'tag2', 'tag3'];
$filteredCollection = $pages->filterBy('tags', 'in', $filterTags);

https://getkirby.com/docs/cheatsheet/pages/filter-by#available-filter-methods


#9

Thank you I’m trying out