# Create relationship between pages in panel

**URL:** <https://forum.getkirby.com/t/create-relationship-between-pages-in-panel/24373>\
**Category:** Questions\
**Tags:** v3\
**Created:** [January 3, 2022, 11:03pm UTC](https://forum.getkirby.com/t/create-relationship-between-pages-in-panel/24373 "2022-01-03T23:03:50Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![kiahr](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/kiahr/32/7169_2.png) [@kiahr](https://forum.getkirby.com/u/kiahr)\
**Post date:** [January 3, 2022, 11:03pm UTC](https://forum.getkirby.com/t/create-relationship-between-pages-in-panel/24373/1 "2022-01-03T23:03:50Z")

</div>

Hello,

I am creating a website, which will be utilised in 2 ways.

1. Organisation will upload information regarding Artists, Artworks & Exhibitions into panel. They will also include note fields here that are hidden from front end. Organisation will use panel for both editing content AND general research, reading of content.

2. Public will access information from front end.

The structure will be:

```auto
Site
  Artists
    Artist
  Artworks
    Artwork
  Exhibitions
    Exhibition

```

An **artist** will be linked to their **artwork** pages, which can be done via a _pages field_.

I was wondering if there was a way to then reflect this page relationship on the artwork page automatically? Perhaps with a query?

I am trying to set this up as it will be important for staff members who view the site primarily through the panel to know what artist/s made the artwork.

Also, trying to keep it as DRY as possible for content editors.

Thank you!

---

<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:** [January 3, 2022, 11:13pm UTC](https://forum.getkirby.com/t/create-relationship-between-pages-in-panel/24373/2 "2022-01-03T23:13:22Z")

</div>

> [@kiahr](#):
>
> I was wondering if there was a way to then reflect this page relationship on the artwork page automatically? Perhaps with a query?

Pages sections don’t allow for queries. But you could create separate sections for artworks by artist in the artworks page with a combination of the pagesdisplay section (plugin: [https://getkirby.com/plugins/rasteiner/pagesdisplay](https://getkirby.com/plugins/rasteiner/pagesdisplay)) and dynamic blueprints ([Add programmable blueprints recipe by texnixe · Pull Request #1569 · getkirby/getkirby.com · GitHub](https://github.com/getkirby/getkirby.com/pull/1569/files))

---

<div class="post-metadata">

**Author:** ![kiahr](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/kiahr/32/7169_2.png) [@kiahr](https://forum.getkirby.com/u/kiahr)\
**Post date:** [January 21, 2022, 4:36pm UTC](https://forum.getkirby.com/t/create-relationship-between-pages-in-panel/24373/3 "2022-01-21T16:36:56Z")

</div>

Hi @texnixe, thanks for the lead.

I have tried resolving it a different way, but am running into an error.

On the “Artwork” page I have the below field:

```auto
artist:
  type: pages
  query: site.children.template('artists').children.template('artist')

```

I am using this model for artist.php:

```auto
<?php

class ArtistPage extends Page
{
    public function getArtworks()
    {
        $artworks = site()->index()->filterBy('intendedTemplate', 'artwork');
        foreach ($artworks as $artwork) 
        {
            $made_by_artist = $artwork->filterBy('artist', $this->uid());
            if ($made_by_artist->count() > 0)
            {
                return array_unique($made_by_artist);
            }
        }
        return false;
    }
}

```

With this section being on the “Artist” page (using the pagesdisplay plugin):

```auto
  artworks:
    headline: Artworks
    type: pagesdisplay
    query: page.getArtworks

```

I am getting this error:

> **The section “artworks” could not be loaded:** Object of class Kirby\Cms\Field could not be converted to int

I am guessing I have not written the model properly?

---

<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:** [January 21, 2022, 4:41pm UTC](https://forum.getkirby.com/t/create-relationship-between-pages-in-panel/24373/4 "2022-01-21T16:41:24Z")

</div>

> [@kiahr](#):
>
> ` $made_by_artist = $artwork->filterBy('artist', $this->uid());`

This line doesn’t make sense. $artwork is a page object which you cannot filter. What do you want to do here?

---

<div class="post-metadata">

**Author:** ![kiahr](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/kiahr/32/7169_2.png) [@kiahr](https://forum.getkirby.com/u/kiahr)\
**Post date:** [January 21, 2022, 4:47pm UTC](https://forum.getkirby.com/t/create-relationship-between-pages-in-panel/24373/5 "2022-01-21T16:47:26Z")

</div>

I guess I am trying to look through all Artwork pages and filter by Artist selected in Artist field.

eg.

If Artwork A, Artwork B & Artwork F all have the page “John Citizen” selected in their Artist fields, then Artwork A, Artwork B & Artwork F will be returned in the page model.

😬

---

<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:** [January 21, 2022, 4:50pm UTC](https://forum.getkirby.com/t/create-relationship-between-pages-in-panel/24373/6 "2022-01-21T16:50:34Z")

</div>

> [@kiahr](#):
>
> `$artworks = site()->index()->filterBy('intendedTemplate', 'artwork');`

Then you have to apply the filter on the `$artworks`:

```auto
 public function getArtworks()
    {
       return site()->index()->filterBy('intendedTemplate', 'artwork')->filter(fn ($artwork) => $artwork->artist()->toPages()->has($this);
    }

```

---

<div class="post-metadata">

**Author:** ![kiahr](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/kiahr/32/7169_2.png) [@kiahr](https://forum.getkirby.com/u/kiahr)\
**Post date:** [January 21, 2022, 4:59pm UTC](https://forum.getkirby.com/t/create-relationship-between-pages-in-panel/24373/7 "2022-01-21T16:59:39Z")

</div>

Thanks so much, that works perfectly.

---

<div class="post-metadata">

**Author:** ![kiahr](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/kiahr/32/7169_2.png) [@kiahr](https://forum.getkirby.com/u/kiahr)\
**Post date:** [April 5, 2024, 12:57am UTC](https://forum.getkirby.com/t/create-relationship-between-pages-in-panel/24373/8 "2024-04-05T00:57:50Z")

</div>

Hi @texnixe, I am working on another site that I am trying to create relationships between Artists, Artworks, Exhibitions etc (like in the previous comments). I noticed that the [pagesdisplay-section](https://github.com/rasteiner/k3-pagesdisplay-section) plugin had been archived by the author. I was wondering if its functionality has been incorporated into Kirby’s core in version 4?

---

<div class="post-metadata">

**Author:** ![kiahr](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/kiahr/32/7169_2.png) [@kiahr](https://forum.getkirby.com/u/kiahr)\
**Post date:** [April 6, 2024, 4:35am UTC](https://forum.getkirby.com/t/create-relationship-between-pages-in-panel/24373/9 "2024-04-06T04:35:42Z")

</div>

Got around to checking today, and yes it is working fine with just the pages section:

```auto
exhibitions:
  headline: Exhibitions
  type: pages
  query: page.getExhibitions
  create: false
  sortable: false

```
