Hi,
I have a problem. There are objects in my system (20 pieces) on the object detail page I would like to show events on which the object was used. I have created a multiselectfield in the event itself where I can select the objects. Unfortunately, I can’t get to the events on the object page because they are saved in the event. Actually, I would have to write the events additionally into the object, is that possible?
My blueprint:
related:
label: Related articles
type: pages
query: site.find('objects').children
Assuming, the parent page of the event pages is events and the multiselect field contains the IDs of the object pages (otherwise, the code would have to be modified):
$objectRelatedEvents = new Pages();
$eventPage. = page('events');
if ( $eventPage ) {
$objectReleatedEvents = $eventPage->children()->listed()->filter(function($event) use ( $page ) {
return in_array($page->id(), $event->multiselectField()->split(','));
});
endif;
That’s what my code is doing, fetching those events that have the current object assigned, according to how you said you stored them, of course, multiselectField() needs to be replaced with the name of the used field.
It’s because you stored the title instead of the id (which is probably not a good idea because likely to change), but you can replace id with title in the php code