2

Basically I’m trying to get en Entry where, either one (or more) of three lightswitches is (are) turned on, or where either categoryOne or categoryTwo is not empty.

This is what I got so far, but it doesn't seem to work.

$criteria = [
    'section' => 'news',
    'limit' => 100,
    'search' => ‘lightswitchOne:1 OR lightswitchTwo:1 OR lightswitchThree:1’,
    'categoryOne' => ':notempty:’,
    'categoryTwo’ => ':notempty:’,
    'id' => 'and, not 1, not 2’//Also exclude a couple id's
];
$criteriaModel = craft()->elements->getCriteria("Entry");
$criteriaModel->setAttributes($criteria);
return $criteriaModel->find();

Is there a way to do this is in Craft?

  • 1
    would you mind adding what worked for you as an official answer in case it helps someone in the future? – Brad Bell Aug 16 '18 at 22:28
0

If found the answer. You can use an * operator in the search query to check if a category field is not empty. So the solution in my case was:

'search' => lightswitchOne:1 OR lightswitchTwo:1 OR lightswitchThree:1 OR categoryOne:* OR categoryTwo:*
| improve this answer | |

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.