Answers.Body: <p><code>true</code>/<code>false</code> are <a href="https://www.php.net/manual/en/language.types.boolean.php" rel="noreferrer">booleans</a>, not <a href="https://www.php.net/manual/en/language.types.string.php" rel="noreferrer">strings</a>, so you shouldn't surround them in quotes:</p>
  
  <pre><code>{% set pinnedNews = craft.entries().section('news').pinned(true).all() %}
  {% set unpinnedNews = craft.entries().section('news').pinned(false).all() %}
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-05-21T02:29:31.163Z
Answers.Text: very good yes programming 101! I promise you this...I set it to (false) then retried, cleared cache, retried, still missing one "false" entry. So I went to that entry, flipped the switch on and off, resaved, tested, bingo. It wasn't until i resaved that i got the correct result. Thank you!
Answers.UserDisplayName: Jim
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-05-21T02:47:46.887Z
Answers.Text: Huh very interesting. Glad it worked! 
Answers.UserDisplayName: Jalen Davenport
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-05-21T03:02:00.303Z
Answers.Text: I've read others have had trouble with switches "sticking". I'll try to find  these.
Answers.UserDisplayName: Jim
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-05-21T02:02:19.213Z
Answers.LastActivityDate: 2019-05-21T02:02:19.213Z
Answers.UserDisplayName: Jalen Davenport
Body: <p>In my news entries, I have a lightswitch field with the handle 'pinned'. I'm trying to query my news section for both pinned and unpinned news entries (true or false essentially), but I can't get consistent results with any of the following:</p>
  
  <pre><code>{% set pinnedNews = craft.entries().section('news').pinned('1').all() %}
  {% set unpinnedNews = craft.entries().section('news').pinned('0').all() %}
  
  {% set pinnedNews = craft.entries().section('news').pinned('true').all() %}
  {% set unpinnedNews = craft.entries().section('news').pinned('false').all() %}
  
  {% set pinnedNews = craft.entries().section('news').pinned('1').all() %}
  {% set unpinnedNews = craft.entries().section('news').pinned('not 1').all() %}
  
  {% set pinnedNews = craft.entries().section('news').search('pinned:1').all() %} THIS WORKS
  {% set unpinnedNews = craft.entries().section('news').search('pinned:0').all() %} DOES NOT WORK
  {% set unpinnedNews = craft.entries().section('news').search('pinned:not 1').all() %} DOES NOT WORK
  </code></pre>
  
  <p>Is there a proper to get the boolean values in Craft 3?</p>
  
Tags: <craft3><lightswitch>
Title: How to query/filter by the value of a lightswitch
ThreadText: # How to query/filter by the value of a lightswitch
  
  (Asked by: username_0 on 2019-05-21)
  
  In my news entries, I have a lightswitch field with the handle 'pinned'. I'm trying to query my news section for both pinned and unpinned news entries (true or false essentially), but I can't get consistent results with any of the following:
  
  ```
  {% set pinnedNews = craft.entries().section('news').pinned('1').all() %}
  {% set unpinnedNews = craft.entries().section('news').pinned('0').all() %}
  
  {% set pinnedNews = craft.entries().section('news').pinned('true').all() %}
  {% set unpinnedNews = craft.entries().section('news').pinned('false').all() %}
  
  {% set pinnedNews = craft.entries().section('news').pinned('1').all() %}
  {% set unpinnedNews = craft.entries().section('news').pinned('not 1').all() %}
  
  {% set pinnedNews = craft.entries().section('news').search('pinned:1').all() %} THIS WORKS
  {% set unpinnedNews = craft.entries().section('news').search('pinned:0').all() %} DOES NOT WORK
  {% set unpinnedNews = craft.entries().section('news').search('pinned:not 1').all() %} DOES NOT WORK
  
  ```
  
  Is there a proper to get the boolean values in Craft 3?
  
  **Tags:** craft3, lightswitch
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2019-05-21. Score: 5 | Accepted answer
  
  `true`/`false` are [booleans](https://www.php.net/manual/en/language.types.boolean.php), not [strings](https://www.php.net/manual/en/language.types.string.php), so you shouldn't surround them in quotes:
  
  ```
  {% set pinnedNews = craft.entries().section('news').pinned(true).all() %}
  {% set unpinnedNews = craft.entries().section('news').pinned(false).all() %}
  
  ```
  
  > **Comments:**
  > **username_0**: very good yes programming 101! I promise you this...I set it to (false) then retried, cleared cache, retried, still missing one "false" entry. So I went to that entry, flipped the switch on and off, resaved, tested, bingo. It wasn't until i resaved that i got the correct result. Thank you!  
  > **username_1**: Huh very interesting. Glad it worked!   
  > **username_0**: I've read others have had trouble with switches "sticking". I'll try to find  these.  
  
  ---
  
  