Filterby multiple tags (2)

Tried to find my answer here but didn’t find it (yet).

I have a collection of artwork items.
Each artwork items has tags.

Artwork 1: ‘Photo’, ‘Painting’, ‘Video’
Artwork 2: ‘Photo’, ‘Video’
Artwork 3: ‘Video’
Artwork 4: ‘Painting’, ‘Video’

  • How can I fetch all artworks who have tag ‘Photo’? (Artwork 1, 2)
  • How can I fetch all artwork who have tags ‘Photo’ or ‘Painting’? (Artwork 1, 2 and 4)

I’m use something like the following code but can’t figure it out fully…

$items = $items->filterBy(‘tags’, ‘in’, [‘Photo’, ‘Painting’]);

Did you try with comma? Because of the tags are stored as a comma separated list:

$items = $items->filterBy('tags', 'in', ['Photo', 'Painting'], ',');
1 Like

Thanks, it works now!