# Searching for pages on a virtual page

**URL:** <https://forum.getkirby.com/t/searching-for-pages-on-a-virtual-page/31102>\
**Category:** Questions\
**Tags:** v3\
**Created:** [March 14, 2024, 1:52pm UTC](https://forum.getkirby.com/t/searching-for-pages-on-a-virtual-page/31102 "2024-03-14T13:52:32Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![timf](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/timf/32/14607_2.png) [@timf](https://forum.getkirby.com/u/timf)\
**Post date:** [March 14, 2024, 1:52pm UTC](https://forum.getkirby.com/t/searching-for-pages-on-a-virtual-page/31102/1 "2024-03-14T13:52:32Z")

</div>

Hello all, this is my first post and English is not my first language so be patient with me.

I’m trying to use a page selector on a virtual page. This is (part of) the template my virtual pages use. Right now I’m on a virtual page called “Emmalaan” which is a subpage of “Werkzaamheden”.

```auto
tabs:
  main:
    label: Algemeen
    columns:
      travelers:
        width: 2/3
        sections:
          travelers:
            type: fields
            fields:
              actions:
                label: Acties voor reizigers
                type: structure
                max: 1
                fields:
                  header:
                    label: Titel
                    type: text
                    default: Acties en tips voor reizigers
                  action_pages:
                    label: Acties en tips voor reizigers
                    type: pages
                    query: site.index.filterBy('template', 'in', ['article'])

```

The `action_pages` is where I’m having trouble. I can select a page just fine, however when i use the search functionality I get an error:

```auto
{
    "status": "error",
    "message": "The page \"werkzaamheden\/emmalaan\" cannot be found",
    "code": 404,
    "exception": "Kirby\\Exception\\NotFoundException",
    "key": "error.page.notFound",
    "file": "\/kirby\/src\/Cms\/Find.php",
    "line": 85,
    "details": [],
    "route": "pages\/([a-zA-Z0-9\\.\\-_%= \\+\\@\\(\\)]+)\/fields\/([a-zA-Z0-9\\.\\-_%= \\+\\@\\(\\)]+)(?:\/(.*))?"
}

```

It seems like it’s trying to reload the virtual page I’m on. But I’m not even selecting a page yet, the error pops op after pressing enter after my search query.

So for clarification, I’m **not** trying to add a virtual page or search for one, I’m trying to search for a regular page **while on a virtual page**.

I appreciatie any help 🙂

---

<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:** [March 14, 2024, 8:59pm UTC](https://forum.getkirby.com/t/searching-for-pages-on-a-virtual-page/31102/2 "2024-03-14T20:59:26Z")

</div>

Hi and welcome to the forum.

Sorry for the late reply, had to set up a test case first, but couldn’t reproduce the issue.

Could you provide the exact steps to reproduce?

Oh, wait, are you still on Kirby 3?

---

<div class="post-metadata">

**Author:** ![timf](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/timf/32/14607_2.png) [@timf](https://forum.getkirby.com/u/timf)\
**Post date:** [March 15, 2024, 1:18pm UTC](https://forum.getkirby.com/t/searching-for-pages-on-a-virtual-page/31102/3 "2024-03-15T13:18:36Z")

</div>

Hello and no worries,

We’re still on kirby 3 yes, we have an internal plugin which doesn’t work with kirby 4 (yet). But this should work with kirby 3 as well right? It seems like a weird bug with the search bar for pages in the panel.

Steps to reproduce:

- We create virtual pages with the internal plugin
- We use a detours page (called “Werkzaamheden”) for an overview of all detour pages (“Emmalaan” is one of those)
- Each detour page has a blueprint, template and a controller. With the “detour” blueprint we can also add subpages. This is the code i just shared (I called it template in my my previous post but I meant blueprint).
- These virtual pages can be accessed from within the panel and the website.
- Whenever i edit a virtual page (by for example adding a subpage), it creates a .txt file for this page, like it’s supposed to. If I don’t edit the page it stays a virtual page and it doesn’t have a .txt file  
\*Editing this page works, I can add text fields, subpages etc. The only thing which doesn’t work is using the search bar in the “action\_pages” field, this happens after typing the search field:

 ![Scherm­afbeelding 2024-03-15 om 14.17.02](https://europe1.discourse-cdn.com/flex017/uploads/getkirby/original/2X/9/9d39fd5d6d2e10f07e575ae755d0aa904c53db54.jpeg)

Here is the part of the plugin where we create the pages using the Pages::factory

```auto
public function children()
    {
        if ($this->children instanceof Pages) {
            return $this->children;
        }

        $search = get('search');
        $status = get('detour_status');
        $areas = get('areas');
        $results = $this->detours($search, $status, $areas);
        $pages = [];

        foreach ($results as $key => $detour) {
            $slug = $detour['slug'];
            $page = $this->subpages()->find($slug);

            $pages[] = [
                'slug' => $detour['slug'],
                'num' => 0,
                'template' => 'detour',
                'model' => 'detour',
                'files' => $page ? $page->files()->toArray() : null,
                'content' => [
                    'title' => $detour['name'],
                    "description" => $detour['description'],
                    "detour_status" => $detour['status'],
                    "slug" => $detour['slug'],
                    "website" => $detour['website'],
                    "cover" => $detour['coverPhoto'],
                    "type" => $detour['detourType'],
                    "fases" => $detour['fases'],
                    "infraManager" => isset($detour['infraManager']) ? $detour['infraManager'] : null,
                    'uuid' => $detour['id'],
                    'actions' => $page ? $page->actions()->value() : null,
                    'employer' => $page ? $page->employer()->value() : null,
                    'logistic' => $page ? $page->logistic()->value() : null,
                ],
            ];
        }

        return $this->children = Pages::factory($pages, $this);
    }

```

$results is filled with data from our internal API.

Do you need anything else?

---

<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:** [March 15, 2024, 2:10pm UTC](https://forum.getkirby.com/t/searching-for-pages-on-a-virtual-page/31102/4 "2024-03-15T14:10:34Z")

</div>

> [@timf](#):
>
> ```auto
> $search = get('search');
> $status = get('detour_status');
> $areas = get('areas');
> $results = $this->detours($search, $status, $areas);
> $pages = [];
> 
> ```

Hm, what is this search code doing in there? That’s probably causing the issue.

---

<div class="post-metadata">

**Author:** ![timf](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/timf/32/14607_2.png) [@timf](https://forum.getkirby.com/u/timf)\
**Post date:** [March 18, 2024, 11:04am UTC](https://forum.getkirby.com/t/searching-for-pages-on-a-virtual-page/31102/5 "2024-03-18T11:04:42Z")

</div>

Wow you’re right!

We use this as a filter for our GRAPHQL query

```auto
 private function detours($search = null, $status = null, $areas = null)
 $query = <<<'GRAPHQL'
query detours($filter: DetoursFilter) {
  detours(filter:$filter) {
    detours {
     <rest of the query>
 }
}
GRAPHQL;

if (isset($search) && !empty($search)) {
    $filter['query'] = $search;
}

<rest of the code>

```

Thanks a lot. I’ll find a different way to filter the query.
