1

I've been attempting to create an entry query that queries the same custom field twice.

Basically I want to check if a custom field is between 2 numbers OR if it is empty. Currently I'm using this to determine if the field is in range

{fieldNumber: ['and', '>=' ~ InputLow, '<=' ~ InputHigh] }

I cannot for the life of me work out how to create an additional OR for fieldNumberin the same query.

I've looked into the Yii orWhere option, but it's separating them with an AND for some reason - I've tried the following as a test

{% set Query = craft.entries(queryParams) %}
{% set Query = Query.orWhere(['between', '`content`.`field_fieldNumber`', "#{1}", "#{300}" ]) %}

it produced the following SQL

 AND (`content`.`field_fieldNumber` BETWEEN 1 AND 300) AND ((`content`.`field_fieldNumber` >= '58') AND (`content`.`field_fieldNumber` <= '62'))...

Ultimately I want a query that will produce something like the below, but I cannot for the life of me work out how to do it.

 AND (`content`.`field_fieldNumber` = null) OR ((`content`.`field_fieldNumber` >= '58') AND (`content`.`field_fieldNumber` <= '62'))...

Has anyone got any ideas, or can anyone point me in the right direction?

Much appreciated.

1

I figured it out in a roundabout way.

orWhere is just an OR join on other orWhere statements.

this collection of orWhere statements is then AND joined to the query.

so in my example I needed to do the following

{% set Query = craft.entries(queryParams) %}
{% set Query = Query.orWhere(['between', '`content`.`field_fieldNumber`', "1", "300" ]) %}
{% set Query = Query.orWhere('`content`.`field_fieldNumber IS NULL') %}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.