Answers.Body: <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>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-11-17T16:30:43.270Z
Answers.Text: 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
Answers.UserDisplayName: migmaker
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-05-31T13:14:32.293Z
Answers.Text: Off switch criteria is: $criteria->myLightswitchField = 'not 1';
Answers.UserDisplayName: Krzysztof Boduch
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-10-07T22:10:04.600Z
Answers.LastActivityDate: 2015-10-07T22:10:04.600Z
Answers.UserDisplayName: Brad Bell
Body: <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>
  
Tags: <plugins><elementcriteriamodel>
Title: Can I use getCriteria to only return entries with a specified lightswitch field set to on?
ThreadText: # 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 username_1. 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';  
  
  ---
  
  