Bit of an unusual one and sure must be missing something but know if we have a defined lightswitch field we want to filter against it can quite easily be done so like this:
{{ craft.products().myField(1) }}
However, if I have several lightswitch fields and a front-end filtering form I don't especially want to explicitly do this against all of them, eg {{ craft.products().myField(1).anotherField(9) }}
. Was wondering then if it is possible to build out some kind of dynamic search or filter but unless doing something crazy looks like the Craft search parameter won't filter against lightswitch fields, eg the following won't work:
{{ craft.products().search('myField:1') }}
I think I have found a workaround using the where()
parameter but feels a bit … inelegant … as essentially specifying my query now against DB values rather than against Craft elements/properties:
{{ craft.products().where('field_myField=1') }}
Any thoughts on improving? Is there a way to do this in native Craft/twig without having to query against specific database values?
Cheers,
Cole
PS above are examples working with Craft Commerce Products. Not entirely sure if this is an issue limited to products as opposed to - say - entries but as these are both essentially elements had assumed not.
php craft resave/products --update-search-index
has resolved. Thanks!