# KQL Plugin: Structure FilterBy Method on pageField

**URL:** <https://forum.getkirby.com/t/kql-plugin-structure-filterby-method-on-pagefield/31437>\
**Category:** Plugins\
**Created:** [April 23, 2024, 12:05pm UTC](https://forum.getkirby.com/t/kql-plugin-structure-filterby-method-on-pagefield/31437 "2024-04-23T12:05:05Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![sweidmann](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/sweidmann/32/7022_2.png) [@sweidmann](https://forum.getkirby.com/u/sweidmann)\
**Post date:** [April 23, 2024, 12:05pm UTC](https://forum.getkirby.com/t/kql-plugin-structure-filterby-method-on-pagefield/31437/1 "2024-04-23T12:05:05Z")

</div>

I want to filter a `structure field` based on the ID of a page selected from one of the pages contained in the structure. The query should work like this:

query: `page.specialExhibitions.toStructure.filterBy('chesas.toPage.id', '==', ${slug} )`,

In this case, `chesas` is the pages field that returns a page. Slug is dynamic, based on the route. The page is a child of another page (`query: 'page("projects").children'`).

Is it possible to filter by the page content (in my case, its ID)?

---

<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:** [April 23, 2024, 12:10pm UTC](https://forum.getkirby.com/t/kql-plugin-structure-filterby-method-on-pagefield/31437/2 "2024-04-23T12:10:41Z")

</div>

> [@sweidmann](#):
>
> chesas.toPage.id’

If this works, then this should read `page.chesas.toPage.id`

---

<div class="post-metadata">

**Author:** ![sweidmann](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/sweidmann/32/7022_2.png) [@sweidmann](https://forum.getkirby.com/u/sweidmann)\
**Post date:** [April 23, 2024, 12:54pm UTC](https://forum.getkirby.com/t/kql-plugin-structure-filterby-method-on-pagefield/31437/3 "2024-04-23T12:54:58Z")

</div>

Unfortunately, that doesn’t work… to specify further, ‘chesas’ is present in the blueprint as a ‘Pages Field’ within the structure:

```auto
            specialExhibitions:
              type: structure                
              fields:
                chesas:
                  label: Chesa
                  type: pages
                  query: site.page('chesas').children
                  multiple: false
                title:
                  type: text
                  label: Titel

```

I also tried ‘structureItem.chesas.toPage.id’ but that didn’t work either. If I would filterBy title

`filterBy('title, '==', 'Some Title' )`

would work… So in my logic …

`filterBy('chesas.toPage.id', '==', ${slug} )`

…should actually be correct?

---

<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:** [April 23, 2024, 1:21pm UTC](https://forum.getkirby.com/t/kql-plugin-structure-filterby-method-on-pagefield/31437/4 "2024-04-23T13:21:46Z")

</div>

> [@sweidmann](#):
>
> filterBy(‘chesas.toPage.id’,

Sorry, didn’t look closely. In php, your filter would have to look like this:

```auto
<?php $res = $page->specialExhibitions()->toStructure()->filter(fn($item) => $item->chesas()->toPage->uuid()->toString() === 'page://X8f4TmwMEq8qZAcR');

```

Since you cannot do this in query language, you need a custom method here.

The pages field stores the uuid if not otherwise defined.

What is `${slug}` in this context?

---

<div class="post-metadata">

**Author:** ![sweidmann](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/sweidmann/32/7022_2.png) [@sweidmann](https://forum.getkirby.com/u/sweidmann)\
**Post date:** [April 23, 2024, 2:09pm UTC](https://forum.getkirby.com/t/kql-plugin-structure-filterby-method-on-pagefield/31437/5 "2024-04-23T14:09:55Z")

</div>

Ok I see… Many thanks for your reply.  
`${slug}` is the route f.ex. `/projects/subpage` and equivalent to the `page.id`.  
I use it to dynamically fetch the content:

```
query: `site.page("${slug}")`,

```

…and since parts of the data comes from other pages i would like to fetch just this certain data in the structure field. (instead of fetching the whole structure data and then filter the collection using JS)
