Collection sorted by field in parents

Hi,

I have a site with the following structure:

Artists
  |- artist-1
  |   |- artwork-1
  |   |- artwork-2
  |   |- artwork-3
  |
  |- artist-2
  |   |- artwork-1
  |   |- artwork-2
  |   |- artwork-3
  |
  |- artist-3
  |   |- artwork-1
  |   |- artwork-2
  |   |- artwork-3

I now need to create a collection of all artworks (which use the artwork template), sorted by a field in the Artist blueprint (lastName). I also want the artworks to appear in the order they are set on the artist page.

What would be the best way of achieving this?

1 Like

Ok I think I have it actually:

return function ($site) {
    return $site->find('art-and-artists')->children()->sortBy('lastName','asc')->children()->published();
};