# Filter subpages in blueprint pages field query

**URL:** <https://forum.getkirby.com/t/filter-subpages-in-blueprint-pages-field-query/21106>\
**Category:** Questions\
**Tags:** v3\
**Created:** [February 6, 2021, 11:39pm UTC](https://forum.getkirby.com/t/filter-subpages-in-blueprint-pages-field-query/21106 "2021-02-06T23:39:24Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![samzzi](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/samzzi/32/11195_2.png) [@samzzi](https://forum.getkirby.com/u/samzzi)\
**Post date:** [February 6, 2021, 11:39pm UTC](https://forum.getkirby.com/t/filter-subpages-in-blueprint-pages-field-query/21106/1 "2021-02-06T23:39:24Z")

</div>

I’ve been searching like crazy but can’t find anything. (maybe I just need to get some sleep 🤔😬)  
I want to apply a filter on both my parent pages as my subpages for page selection but it only seems to be working on the parent page.

Blueprint

```auto
buttonLinkPage:
    label: Page
    type: pages
    multiple: false
    subpages: true
    image: icon
    query: kirby.collection('pages')
    link: false

```

Collection

```php
return function($site)
{
    return $site->pages()->filter(function($page) {
        return $page->filterBy('template', '^=', 'page') || $page->template(['home', 'default', 'error']);
    })->sortBy('title');
};

```

Other attempt for a collection

```php
return function($site)
{
    return $site->pages()->filter(function($page) {
        return $page->filterBy('template', '^=', 'page') || $page->template(['home', 'default', 'error']);
    })->filter(function($child) {
        return $child->filterBy('template', '^=', 'page') || $child->template(['home', 'default', 'error']);
    })->sortBy('title');
};

```

---

<div class="post-metadata">

**Author:** ![jimbobrjames](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/jimbobrjames/32/5802_2.png) [@jimbobrjames](https://forum.getkirby.com/u/jimbobrjames)\
**Post date:** [February 7, 2021, 12:08am UTC](https://forum.getkirby.com/t/filter-subpages-in-blueprint-pages-field-query/21106/2 "2021-02-07T00:08:50Z")

</div>

Unless ive missed what you are trying to do here, you can filter on multiple templates in the collection, and go through the whole site index…

```auto
$site->index()->filterBy('template', 'in', ['page', 'home', 'default', 'error');

```

Source: [$pages-\>filterBy() | Kirby](https://getkirby.com/docs/reference/objects/pages/filter-by)

```auto
<?php

return function ($site) {
    return $site->index()->filterBy('template', 'in', ['page', 'home', 'default', 'error')->sortBy('title');
};

```

---

<div class="post-metadata">

**Author:** ![samzzi](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/samzzi/32/11195_2.png) [@samzzi](https://forum.getkirby.com/u/samzzi)\
**Post date:** [February 7, 2021, 12:38am UTC](https://forum.getkirby.com/t/filter-subpages-in-blueprint-pages-field-query/21106/3 "2021-02-07T00:38:58Z")

</div>

If you do `subpages: false` this indeed works but if you do `subpages: true` then the filter only works on the first level.

For example. I have a subpage “this should not be here” with template “whatever”. When i filter on index with `subpages: false` I don’t see it, like expected.

`query: site.index.filterBy('intendedTemplate', 'in', ['home', 'default'])`

![CleanShot 2021-02-07 at 01.34.38](https://europe1.discourse-cdn.com/flex017/uploads/getkirby/original/2X/f/f7297ed60c484f227e311ed4b71e5d9fadcb2f79.jpeg)

But if I use that same query with `subpages: true` and I go to the subpage, I do see that page.

![CleanShot 2021-02-07 at 01.36.23](https://europe1.discourse-cdn.com/flex017/uploads/getkirby/original/2X/c/c88f4681f1b75879dff41bf40cc2d3e500624ea7.jpeg)

![CleanShot 2021-02-07 at 01.36.53](https://europe1.discourse-cdn.com/flex017/uploads/getkirby/original/2X/c/c43a976d0842e3b6062c7c2a19247847f70ad026.jpeg)

But I don’t want to see that page there. I only want everything with template home and default.

---

<div class="post-metadata">

**Author:** ![texnixe](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/texnixe/32/5754_2.png) [@texnixe](https://forum.getkirby.com/u/texnixe)\
**Post date:** [February 7, 2021, 1:12am UTC](https://forum.getkirby.com/t/filter-subpages-in-blueprint-pages-field-query/21106/4 "2021-02-07T01:12:40Z")

</div>

> [@samzzi](#):
>
> ` return $page->filterBy('template', '^=', 'page') || $page->template(['home', 'default', 'error']);`

This cannot possibly work, because you cannot filter a page object.

---

<div class="post-metadata">

**Author:** ![samzzi](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/samzzi/32/11195_2.png) [@samzzi](https://forum.getkirby.com/u/samzzi)\
**Post date:** [February 7, 2021, 1:58am UTC](https://forum.getkirby.com/t/filter-subpages-in-blueprint-pages-field-query/21106/5 "2021-02-07T01:58:14Z")

</div>

Is there any other way to achieve [this](https://forum.getkirby.com/t/filter-subpages-in-blueprint-pages-field-query/21106/3) then? I was just trying everything I could think of to get some sort of filter on the subpages or am I trying to do something impossible and is the index one the way to go? (would be good UX to be able to work with the drilldown subpage functionality though)

Cheers!

Sam

---

<div class="post-metadata">

**Author:** ![texnixe](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/texnixe/32/5754_2.png) [@texnixe](https://forum.getkirby.com/u/texnixe)\
**Post date:** [February 7, 2021, 11:16am UTC](https://forum.getkirby.com/t/filter-subpages-in-blueprint-pages-field-query/21106/6 "2021-02-07T11:16:03Z")

</div>

No, this won’t work. The purpose of the subpages’ property is to control whether to show subpages of the queried selection or not. The alternative is a flat collection of filtered pages without drilldown.

Or a custom field…

---

<div class="post-metadata">

**Author:** ![Ove](https://avatars.discourse-cdn.com/v4/letter/o/f475e1/32.png) [@Ove](https://forum.getkirby.com/u/Ove)\
**Post date:** [June 12, 2025, 3:10pm UTC](https://forum.getkirby.com/t/filter-subpages-in-blueprint-pages-field-query/21106/7 "2025-06-12T15:10:06Z")

</div>

Had the same issue and created a custom field extending the core pages field and PagePicker class so a `filter-query` can be applies to subpages aswell.

> **[GitHub - Basics09/kirby-pagesfilter-field](https://github.com/Basics09/kirby-pagesfilter-field)**
>
> Contribute to Basics09/kirby-pagesfilter-field development by creating an account on GitHub.

For now only comopser install is supported.
