Skip to content

[5.x]: Element query param "not 1" no longer works as expected for Lightswitch fields since 5.7 #17149

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
mmikkel opened this issue Apr 22, 2025 · 1 comment
Labels

Comments

@mmikkel
Copy link
Contributor

mmikkel commented Apr 22, 2025

What happened?

Description

Since updating to Craft 5.7, using the 'not 1' syntax for Lightswitch element query params no longer works as expected – i.e. instead of returning elements that doesn't have the Lightswitch field enabled, it now does the opposite and only returns elements where the Lightswitch field is enabled.

FWIW, I know that the 'not 1' syntax isn't actually mentioned in the Lightswitch docs, so this might be an intended change to remove a behavior that hasn't actually been officially supported for a while. Still feels like a breaking change, though.

Steps to reproduce

  1. Create some entries using an entry type that includes a Lightswitch field. Make sure some entries have the Lightswitch field set to enabled, and others to disabled.

  2. Execute the following element query:

{% set entries = craft.entries.lightswitchField('not 1').all() %}

On Craft 5.6.17, this query will return any entry that doesn't have the lightswitchField enabled.

On Craft 5.7.1.1, this query will return entries that does have the lightswitchField enabled.

Expected behavior

Querying elements using 'not 1' for a Lightswitch element query param should return elements that doesn't have the Lightswitch enabled.

Actual behavior

Elements that have the Lightswitch field enabled are returned.

Craft CMS version

5.7.1.1

PHP version

8.3.19

Operating system and version

DDEV v1.24.4

Database type and version

MySQL 8.0.40

Image driver and version

No response

Installed plugins and versions

None

@brandonkelly
Copy link
Member

Thanks for reporting that! Craft 5.7.2 is out with a fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants