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
  • 1
    would you mind adding what worked for you as an official answer in case it helps someone in the future?
    – Brad Bell
    Commented Aug 16, 2018 at 22:28

1 Answer 1

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:*

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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