Select related pages with KQL

I found the solution here: How to create "related pages" field, where related pages would be selected from other page children? - #3 by Roman

Apparently I have to call the method toPages on the related page.

Full working query:

{
            query: "site",
            select: {
              title: "site.title",
              url: "site.url",
              products: {
                query: "page('products').children.listed",
                select: {
                  id: true,
                  title: true,
                  category: {
                      query: "page.category.toPages",
                      select: {
                          id: true,
                          headline: true,
                      }
                  }
                }
              },
            }
          }
1 Like