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
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 5 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
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
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
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
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
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
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
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
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
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
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