Filtering Pages by multiselect from another Page

Hi,

i can’t get my head around my little problem.
In my project i have several tours defined.

Tours

  • Tour A
  • Tour B
  • etc.

Each tour has the following miltiselect

protagonisten:
            label: Protagonisten
            type: multiselect
            options: query
            query:
              fetch: site.find('Protagonists').children.listed
              text: "{{page.title}}"
              value: "{{page.title}}"

Now i need a list of all Protagonists pages which are selected in my tour pages.

Can anyone help?

First of all I wouldn’t use the title as value but the id. While the id might also change, the title is much more likely to change and it’s a lot easier to turn the values into pages.

Not quite sure what you want to filter and where. Do you mean to get a list of all protagonists which are selected in any one of the tours?

Or do you want to get the protagonist pages from the values in the multiselect from a single tour?

Hey,

thanks for the answer.
I know the title is not the best way to store the info but i can’t change it right now.

in my template i want to get the protagonist pages which are selected in any one of the tours.

Something like this should work:

$protagonists = null;
if ($tours = page('tours') && $protagonists = page('protagonists')) {
  $titles = $tours->children()->listed()->pluck('protagonisten', ',', true);
  $protagonists = $protagonists->filterby('title', 'in', $titles);
}
if ($protagonists && $protagonists->isNotEmpty()) {
  // do stuff
}

Perfect. It’s works like a charm.

Thanks a lot.