How to query/filter by the value of a lightswitchUsing 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
Navigating a quick return to previous employer
Why'd a rational buyer offer to buy with no conditions precedent?
Flatten not working
Is superuser the same as root?
Physical only checkdb is failing, but full one is completed successfully
Quantum corrections to geometry
Question about Shemot, locusts
Why do Russians almost not use verbs of possession akin to "have"?
Who wrote “A writer only begins a book. A reader finishes it.”?
One word for 'the thing that attracts me'?
Storing voxels for a voxel Engine in C++
"Official wife" or "Formal wife"?
Is keeping the forking link on a true fork necessary (Github/GPL)?
Are there historical examples of audiences drawn to a work that was "so bad it's good"?
What could be my risk mitigation strategies if my client wants to contract UAT?
How to escape dependency hell?
Are cells guaranteed to get at least one mitochondrion when they divide?
Why did OJ Simpson's trial take 9 months?
Does water in vacuum form a solid shell or freeze solid?
To exponential digit growth and beyond!
Status of proof by contradiction and excluded middle throughout the history of mathematics?
Are PMR446 walkie-talkies legal in Switzerland?
Why does the Starter Set wizard have six spells in their spellbook?
How do you earn the reader's trust?
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
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
add a comment |
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
add a comment |
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
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
craft3 lightswitch
asked 4 hours ago
JimJim
475
475
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
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() %
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
3 hours ago
Huh very interesting. Glad it worked! 🙌
– Jalen Davenport
3 hours ago
I've read others have had trouble with switches "sticking". I'll try to find these.
– Jim
3 hours ago
add a comment |
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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() %
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
3 hours ago
Huh very interesting. Glad it worked! 🙌
– Jalen Davenport
3 hours ago
I've read others have had trouble with switches "sticking". I'll try to find these.
– Jim
3 hours ago
add a comment |
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() %
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
3 hours ago
Huh very interesting. Glad it worked! 🙌
– Jalen Davenport
3 hours ago
I've read others have had trouble with switches "sticking". I'll try to find these.
– Jim
3 hours ago
add a comment |
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() %
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() %
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
3 hours ago
Huh very interesting. Glad it worked! 🙌
– Jalen Davenport
3 hours ago
I've read others have had trouble with switches "sticking". I'll try to find these.
– Jim
3 hours ago
add a comment |
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
3 hours ago
Huh very interesting. Glad it worked! 🙌
– Jalen Davenport
3 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
3 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
3 hours ago
Huh very interesting. Glad it worked! 🙌
– Jalen Davenport
3 hours ago
Huh very interesting. Glad it worked! 🙌
– Jalen Davenport
3 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
add a comment |
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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