Showing with A OR B tags from taxonomy

Hi there,

Just a simple one here. In my frontmatter, I would like to create a collection using that pulls in anything tagged with “oranges” OR “apples”. When defined as below, it only brings in things tagged with BOTH “oranges” AND “apples”. Is there a simple way to define the collection such that any post tagged with either of the tags is in the collection?

title: 'Oranges & Apples'
content:
    items:
        '@taxonomy.tag':
            - oranges
            - apples
    order:
        by: date
        dir: desc
    limit: 5
    pagination: true

See Collection::merge($collection2)

1 Like

I would add this:
You need en array, it will be written between squared brackets: [ ]

content:
items:
   '@taxonomy.tag': [foo, bar]

I’m afraid this doesn’t help me. It lists pages tagged only with foo AND bar. Not foo OR bar (or both)

Thank you. Could you give me any pointers on how to use this method? It seems like it is what I am looking for but I can’t quite figure out how to use it. Is it called in the Frontmatter or does it need to be part of the Twig code in the main page?

Scroll up and you’ll see the basic example: https://learn.getgrav.org/16/content/collections#multiple-collections.

Create the two collections, then iterate over the merge:

<h3>Merged</h3>
<ul>
{% for p in collection1.merge(collection2) %}
<li>{{ p.title }}</li>
{% endfor %}
</ul>
1 Like

Oh, I can’t believe I had overlooked that! Thanks for your help.

And an update in case if anybody else wants to do the same thing - I tried this as @Perlkonig said and it worked perfectly. Thanks for the help!