Need help with a somewhat complex search #13827
-
Hi all, I need some help with some searching logic. I could do a check on this 'relatedThemes' field after I've run the query, but that original query gets used for pagination. So there would be a mismatch in counts between the two. So ideally, I would want to add this restriction on to my query. I was thinking about using relatedTo, something to this effect:
However, I'm not sure as to how this would behave, with regards to the other sections. I have a feeling that this setup would only give me events related to 'hiking', and ommit 'partners' and 'equipment' alltogether. Any tips or insights in how I could set this up would be greatly appreciated! |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
@JulieVelghe you could simply let your query end and return a collection, then you can use collection methods to filter your data further. |
Beta Was this translation helpful? Give feedback.
-
One way to do it is you could start by getting all the entry IDs you don’t want, and then telling your main query to exclude them. $hikingId = Entry::find()
->section('themes') // change this as needed
->slug('hiking')
->ids();
$hikingThemedEntryIds = Entry::find()
->section(['events', 'partners', 'equipment'])
->relatedTo([
'targetElement' => $hikingId,
'field' => 'relatedThemes'
])
->ids();
$entries = Entry::find()
->section(['events', 'partners', 'equipment'])
->id(array_merge(['not'], $hikingThemedEntryIds))
->siteId([1, 2])
->search($query)
->orderBy('score'); |
Beta Was this translation helpful? Give feedback.
One way to do it is you could start by getting all the entry IDs you don’t want, and then telling your main query to exclude them.