Related Posts from a Structure Field

Hello everyone.
I have a piece of working code here.

fields:
  menschen:
    type: multiselect
    options: query
    query: site.page("menschen").children
<?php
  $engagiertIn = $pages->find('spielzeiten')->children()->children()
    ->filter(function($child) use($page) {
    return $child->menschen()->toPages(',')->has($page);
  }); 
?>

But! Now I should change this because the “menschen” from the multiselect have now been moved to a structure. I don’t understand how I have to rebuild the part with the :x: so that it works again. Can anybody help?

fields:
  menschen:
    type: structure
    fields:
      rolle:
        type: text
      mensch:
        type: multiselect
        options: query
        query: site.page("menschen").children
<?php
  $engagiertIn = $pages->find('spielzeiten')->children()->children()
    ->filter(function($child) use($page) {
    // ❌ return $child->menschen()->toPages(',')->has($page);
  }); 
?>

You would have to collect all mensch from your structure into a pages collection:

  $engagiertIn = $pages->find('spielzeiten')->children()->children()
    ->filter(function($child) use($page) {
        $people = new Pages();
        foreach ($child->menschen()->toStructure() as $item) {
          $people->add($item->mensch()->toPages(',');
        }
       return $people->has($page);
  }); 

You are aware that you could use a pages field instead of the multiselect?

Thank you very much for that.

No. I didn’t realize I could use a pages field.
If flew over the docs docs and couldn’t find any benefit.
I think I’ll check this out later.

:sunny: