How to query/filter by the value of a lightswitchUsing a Lightswitch to insert a class on a body's tagOnly...

Flatten not working

Is a world with one country feeding everyone possible?

Piping the output of comand columns

Possibility of faking someone's public key

How do you earn the reader's trust?

Status of proof by contradiction and excluded middle throughout the history of mathematics?

Why does FOO=bar; export the variable into my environment

Navigating a quick return to previous employer

What is the purpose of the yellow wired panels on the IBM 360 Model 20?

Papers on ArXiv as main references

Gravitational Force Between Numbers

Why does Bran want to find Drogon?

Visual Block Mode edit with sequential number

Testing using real data of the customer

Physical only checkdb is failing, but full one is completed successfully

Why is 'additive' EQ more difficult to use than 'subtractive'?

Where is Jon going?

What is the use case for non-breathable waterproof pants?

Cisco 3750X Power Cable

What is Orcus doing with Mind Flayers in the art on the last page of Volo's Guide to Monsters?

Why A=2 and B=1 in the call signs for Spirit and Opportunity?

To exponential digit growth and beyond!

How to create a `range`-like iterable object of floats?

Why is std::ssize() introduced in C++20?



How to query/filter by the value of a lightswitch


Using a Lightswitch to insert a class on a body's tagOnly allow one Lightswitch to be active at a timeHow can I query for entries that have one of two Lightswitch fields enabled?Update checkbox value through plugin (Craft 3)Showing entries for light switchFiltering by categories AND tags with full matchHow to include asset fields in query in php?Element API SearchQuery to search for value inside child-entriesHow to limit Expanded Search (plugin) query results for pagination?Query on Super Table field's entry field













1















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?










share|improve this question



























    1















    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?










    share|improve this question

























      1












      1








      1








      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?










      share|improve this question














      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?







      craft3 lightswitch






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked 5 hours ago









      JimJim

      475




      475






















          1 Answer
          1






          active

          oldest

          votes


















          2














          true/false are booleans, not strings, 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() %}





          share|improve this answer



















          • 1





            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!

            – Jim
            4 hours ago











          • Huh very interesting. Glad it worked! 🙌

            – Jalen Davenport
            4 hours ago











          • I've read others have had trouble with switches "sticking". I'll try to find these.

            – Jim
            3 hours ago












          Your Answer








          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "563"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: false,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcraftcms.stackexchange.com%2fquestions%2f30463%2fhow-to-query-filter-by-the-value-of-a-lightswitch%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          2














          true/false are booleans, not strings, 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() %}





          share|improve this answer



















          • 1





            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!

            – Jim
            4 hours ago











          • Huh very interesting. Glad it worked! 🙌

            – Jalen Davenport
            4 hours ago











          • I've read others have had trouble with switches "sticking". I'll try to find these.

            – Jim
            3 hours ago
















          2














          true/false are booleans, not strings, 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() %}





          share|improve this answer



















          • 1





            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!

            – Jim
            4 hours ago











          • Huh very interesting. Glad it worked! 🙌

            – Jalen Davenport
            4 hours ago











          • I've read others have had trouble with switches "sticking". I'll try to find these.

            – Jim
            3 hours ago














          2












          2








          2







          true/false are booleans, not strings, 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() %}





          share|improve this answer













          true/false are booleans, not strings, 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() %}






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered 4 hours ago









          Jalen DavenportJalen Davenport

          1,804318




          1,804318








          • 1





            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!

            – Jim
            4 hours ago











          • Huh very interesting. Glad it worked! 🙌

            – Jalen Davenport
            4 hours ago











          • I've read others have had trouble with switches "sticking". I'll try to find these.

            – Jim
            3 hours ago














          • 1





            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!

            – Jim
            4 hours ago











          • Huh very interesting. Glad it worked! 🙌

            – Jalen Davenport
            4 hours ago











          • I've read others have had trouble with switches "sticking". I'll try to find these.

            – Jim
            3 hours ago








          1




          1





          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!

          – Jim
          4 hours ago





          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!

          – Jim
          4 hours ago













          Huh very interesting. Glad it worked! 🙌

          – Jalen Davenport
          4 hours ago





          Huh very interesting. Glad it worked! 🙌

          – Jalen Davenport
          4 hours ago













          I've read others have had trouble with switches "sticking". I'll try to find these.

          – Jim
          3 hours ago





          I've read others have had trouble with switches "sticking". I'll try to find these.

          – Jim
          3 hours ago


















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Craft CMS Stack Exchange!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcraftcms.stackexchange.com%2fquestions%2f30463%2fhow-to-query-filter-by-the-value-of-a-lightswitch%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Taj Mahal Inhaltsverzeichnis Aufbau | Geschichte | 350-Jahr-Feier | Heutige Bedeutung | Siehe auch |...

          Baia Sprie Cuprins Etimologie | Istorie | Demografie | Politică și administrație | Arii naturale...

          Ciclooctatetraenă Vezi și | Bibliografie | Meniu de navigare637866text4148569-500570979m