1

I'm building a plugin that will check all existing entries in a section when a single entry is flagged as featured and turn off any existing featured entries. I'm using a lightswitch field to turn on and off entries. Is there a way to use the craft()->elements->getCriteria(ElementType::Entry); to return just the entries with the lightswitch field turned on?

Cheers

1 Answer 1

3

This should do it:

$criteria = craft()->elements->getCriteria(ElementType::Entry);
$criteria->section = 'mySection';
$criteria->myLightswitchField = 1;
$entries = $criteria->find();
2

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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