Pages Fields Relationships

Hello, I am new to Kirby but I’m loving it so far!

I currently have two page types one called “Projects” and the other called “Artists”. In both pages, I have a pages field where I can select multiple pages of the other page type. How would I create a relationship so when I add a related “Project” page to the “Artist” page field, it also adds the current “Artist” page to that related “Project” page?

Thanks in advanced :slight_smile:

The question is if it isn’t completely sufficient if this information is available in the project page.

If you then want to list the projects that belong to a given artist, you can filter the projects by artist.

This way you can still have your many-to-many relationship but without having to duplicate the relations.

If you still want to do this, you can use hooks.

When working with relationships, I’d recommend using the AutoID plugin to give each page a unique key that is then stored as reference (foreign key). This is necessary to make sure that the reference to the page is still valid in the future, even if the referenced page is later deleted.

Thanks for getting me started! My only question is how do you use AutoID with the pages field? In the documentation, it shows how to use the AudioID with a structured field but I don’t see anything about how to use it with the pages field. Thanks again

I’m afraid it won’t work with a pages field, because you need a query option that accepts an array, i.e. a select or multiselect field:

    type: multiselect
    label: Related pages
    options: query
      fetch: page("notes").children
      text: "{{ page.title }}"
      value: "{{ page.autoid }}"  

Is this still the case? I’m currently upgrading a K2 page with a page-select field (I used the now discontinued “quickselect” plugin to store the autoid value).

Can I use the pages field or do I have to use the select field with a pages query?


Yes, you cannot set a value to store for the pages field.

1 Like