Skip to content

Need help with a somewhat complex search #13827

Closed Answered by brandonkelly
JulieVelghe asked this question in Q&A
Discussion options

You must be logged in to vote

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');

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
1 reply
@JulieVelghe
Comment options

Comment options

You must be logged in to vote
0 replies
Answer selected by brandonkelly
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants