Taxonomy filtering not working

Hello, I’m trying to filter for category and tag in a news collection. How do i get this to work? The news getting displayed but not filtered at all:

---
content:
    items:
        '@page.children': '/news'
        '@taxonomy': {category: [Blog], tag: [Spielbericht]}
    leading: 0
    columns: 1
    limit: 5
    order:
        by: date
        dir: desc
    show_date: true
    pagination: true
    url_taxonomy_filters: true
---

I’ve also tried the different variants described here: https://learn.getgrav.org/17/content/collections#page-collections without any effect.

@dapu,

See Complex Collections:

You can also provide multiple complex collection definitions and the resulting collection will be the sum of all the pages found from each of the collection definitions. For example:

content:
  items:
    - '@self.children'
    - '@taxonomy':
         category: [blog, featured]
1 Like

@dapu, Any progress you might be able to share?

I’ve tried this:

---
content:
    items:
        '@page.pages': /news
        '@taxonomy':
            category: Blog
            tag: Spielbericht
    leading: 0
    columns: 1
    limit: 5
    order:
        by: date
        dir: desc
    show_date: true
    pagination: true
    url_taxonomy_filters: true
---

But it’s not working. The blog list is showing all of the news pages. It looks like the taxonomy is completely ignored. When I use the taxonomy filtering directly on the collection it works:

// user/themes/theme_name/templates/blog_list.html.twig
{% set collection = page.collection( {'items':{'@taxonomy':{'category': 'Blog', 'tag': 'Spielbericht'}}} ) %}

@dapu, As said before, a collection definition containing multiple collections combines the results of all defined collections.

The following collection contains all child pages of page /news plus all pages with category: Blog and tag: Spielbericht.
Meaning: If all taxonomy pages are in folder /news, the taxonomy filter has no effect, because all pages below /news are already included in the collection.

content:
    items:
        '@page.pages': /news
        '@taxonomy':
            category: Blog
            tag: Spielbericht

See the docs on @page.children:

@page.children - Children of a specific page
This collection takes a slug route of a page as an argument and will return all the published children of that page:

content:
   items:
    '@page.children': '/blog'

An alias of '@page.pages': '/blog' is also valid. Using '@page': '/blog' is deprecated as its meaning can change in the future.

Pay attention to the last paragraph which states that @page.pages: /blog is an alias for '@page.children': '/blog'

If above does not answer your question, then what is your interpretation of your own collection definition and what result do you expect?

1 Like