1
$criteria = craft()->elements->getCriteria(ElementType::Entry);
$criteria->section = 'stories';
$criteria->search = $this->query;
$criteria->order = $this->orderSql();
$criteria->limit = 1000;
$criteria->visibility = $this->checkVisibility();
$criteria->thisIsAGuide = ':empty:';

I need help adding a relatedTo criteria to help pull related entries.

The current search scope is searching on entries ("Story"). The entry("Story") contains an entry ("channel"). That channel has a category("brandCategories")

I need to return stories that contain entries that have a matching brandCategory. That brandCategory is getting pulled from a GET var of "&brands%5B%5D={{categoryId}}

2

You can create 2 queries, first you pull all the channel entries, that are related to your bandCategory

$criteria = craft()->elements->getCriteria(ElementType::Entry);
$criteria->relatedTo = $bandCategory;
$criteria->section = 'channel';
$relatedChannelEntries = $criteria->ids();

// then continue your code 
$criteria = craft()->elements->getCriteria(ElementType::Entry);
$criteria->section = 'stories';
$criteria->search = $this->query;
$criteria->order = $this->orderSql();
$criteria->limit = 1000;
$criteria->visibility = $this->checkVisibility();
$criteria->thisIsAGuide = ':empty:';
// and search only for entries that are related to channel entries that are related to your band
$criteria->relatedTo = $relatedChannelEntries;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.