I'm trying to exclude entries that are tagged "DO NOT PROMOTE" on any page where craft.entries is used minus their actual entry page.
What I've come up with so far is this:
public function init()
{
parent::init();
/*
Exclude DO NOT PROMOTE tagged entries
*/
// Get DO NOT PROMOTE tag id
$tagCriteria = craft()->elements->getCriteria(ElementType::Tag);
$tagCriteria->title = 'DO NOT PROMOTE';
$tag = $tagCriteria->first();
// Get Entries related to above tag
$entryCriteria = craft()->elements->getCriteria(ElementType::Entry);
$entryCriteria->limit = null;
$entryCriteria->status = null;
$entryCriteria->relatedTo = [
'targetElement' => $tag,
'field' => 'tags'
];
$doNotPromoteEntries = $entryCriteria->ids();
craft()->on('elements.beforeBuildElementsQuery', function(Event $event) use ($doNotPromoteEntries) {
$criteria = $event->params['criteria'];
$criteria->id = 'and, not ' . implode(', not ', $doNotPromoteEntries);
});
}
Now this kind of works. The issue I'm running into is the homepage is now showing an entry post... which is should not be. So, my modifying the criteria has caused this issue.
Is there a more eloquent or better way to accomplish this?