I have three types of content, with two page reference fields linking them.
work
/ \
work_exhibition work_artist
/ \
exhibition artist
On the Exhibition template, I want to show all artists that appear in an exhibition, and beneath each artist all works that are both by them and in the exhibition.
I have the following code:
<?php foreach ($pages->find("template=work, work_exhibition=$page->path") as $workIds):?>
<?php foreach ($pages->find("template=artist, title={$workIds->work_artist->title}") as $artist):?>
<strong><?= $artist->title; ?></strong><br>
<?= $workIds->title; ?><br><br>
<?php endforeach; ?>
<?php endforeach; ?>
Which is giving me (e.g.):
Artist 1
Work
Artist 1
Work
Artist 2
Work
I'd like it to instead show:
Artist 1
Work
Work
Artist 2
Work
I've tried using "->unique()" but wasn't sure where to put it. Or maybe I need to go about this some other way. Any pointers appreciated.