<p>This should do it:</p>

<pre><code>$criteria = craft()-&gt;elements-&gt;getCriteria(ElementType::Entry);
$criteria-&gt;section = 'mySection';
$criteria-&gt;myLightswitchField = 1;
$entries = $criteria-&gt;find();
</code></pre>

CC BY-SA 3.0
2015-11-17T16:30:43.270Z
Hi Brad. Is it possible to do that with a OR condition on two fields ? http://craftcms.stackexchange.com/questions/12421/use-getcriteria-with-or-condition-on-multiple-fields
migmaker
CC BY-SA 3.0
2017-05-31T13:14:32.293Z
Off switch criteria is: $criteria->myLightswitchField = 'not 1';
Krzysztof Boduch
CC BY-SA 3.0
2015-10-07T22:10:04.600Z
2015-10-07T22:10:04.600Z
Brad Bell
<p>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 <code>craft()-&gt;elements-&gt;getCriteria(ElementType::Entry);</code> to return just the entries with the lightswitch field turned on?</p>

<p>Cheers</p>

<plugins><elementcriteriamodel>
Can I use getCriteria to only return entries with a specified lightswitch field set to on?
# Can I use getCriteria to only return entries with a specified lightswitch field set to on?

(Asked by: username_0 on 2015-10-07)

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

**Tags:** plugins, elementcriteriamodel

---

## 1 answers

### Answer by username_1 on 2015-10-07. Score: 3 | Accepted answer

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

> **Comments:**
> **username_2**: Hi Brad. Is it possible to do that with a OR condition on two fields ? http://craftcms.stackexchange.com/questions/12421/use-getcriteria-with-or-condition-on-multiple-fields  
> **username_3**: Off switch criteria is: $criteria->myLightswitchField = 'not 1';  

---

