Check if a page of a structure field is on another page

Hello, I have an event page which also shows speakers from my speakers detail page. I want to see on which event the speaker is talking. Is it possible to get this ouput automatically or do I need to set it all by myself for each speaker?

Currently I have a structure field on the speakers detail page to select the event the speaker is talking, but as I said, I want to avoid to set the event for every speaker since I already defined the speakers for each event.

I hope I didn’t describe it too complex. Thanks everyone in advance :slight_smile:

I guess the speaker is then selected on the event page to relate them to the event, right? What field type do you use to select the speaker? Can there be multiple speakers assigned to an event?

Then you can filter your events by speaker name.

Edit: Please choose the question category that corresponds to your Kirby version when creating a topic. You don’t even indicate in your text which version your are using.

Thanks for your message and sorry I didn’t ask right. I edited the topic : )

I am using a structure field to select the speaker to the event. And yes, on the event page it is possible to assign multiple speakers. It looks like this on the event page:

    label: Speaker
    type: structure
        label: Select Speaker
        type: select
        options: query
        query: site.find('speaker').children
    label: Host
    type: structure
        label: Select Host
        type: select
        options: query
        query: site.find('hosts').children

Ok, then it is slightly more complicated:

$speaker = "uid of speaker"; 
$speakerEvents = page('events')->children()->filter(function($child) use($speaker) {
  $speakers = $child->speaker()->toStructure();
  return $speakers->findBy('selectspeaker', $speaker);

Thanks! I tried it like this:

<?php $speaker = $page->uid();
    $speakerEvents = page('program')->grandChildren()->filter(function($child) use($speaker) {
        $speakers = $child->speaker()->toStructure();
        return $speakers->findBy('selectspeaker', $speaker);

I get the Idea, but unfortunately it’s not working. still thinking …

What is stored in the selectspeaker structure field?

It is the page of the speaker

Well, yes, of course, but what I meant is: What information about the page is stored, the UID?

Hm maybe I am not to deep into this.
But maybe this helps how I fetched the informations from the speakers page on another page:

<?php foreach($subpage->speaker()->toStructure() as $speaker): $speakerdetail = $speaker->selecthost()->toPage(); if($speakerdetail): ?>
		<h2><?= $speakerdetail->title() ?></h2>
		<h3><?= $speakerdetail->company() ?></h3>
  <?php endif ?>
<?php endforeach ?>

I think the URI is stored instead of the UID (but you don’t want to tell me, so this is guesswork), then you would have to adapt your code.

$speaker = $page->uri();

$speakerEvents = page('program')->grandchildren()->filter(function($child) use($speaker) {
  $speakers = $child->speaker()->toStructure();
  return $speakers->findBy('selectspeaker', $speaker);

I think its looking good. I get the two related events as:

Kirby\Cms\Pages Object
    [0] => program/wednesday/spaces-on-wheels
    [1] => program/thursday/framelab