MODX Community

MIGX where condition with "or"

In the docs there’s an example where condition {"active:=":"1","rating:>":"5"} - but that’s an AND condition. How do I code an OR? Something like {"active:=":"1","rating:>":"5", "OR:rating:=":"1"} doesn’t work.

I’d like to use it for an event calendar which can have single and multi day events. Start date is required, end date is optional. In SQL I’d write STARTDATE >= CURRENT_DATE And (ENDDATE Is Null Or ENDDATE >= CURRENT_DATE)

Are you talking about getImageList or migxLoopCollection?

I believe with getImageList OR-conditions are not possible. Maybe you could use a snippet in the &where property

[[getImageList? ... &where=`{"enddate:snippet:mygetimagelistsnippet":""}`]]

Then create a snippet mygetimagelistsnippet:

<?php
$enddate = $modx->getOption('subject', $scriptProperties, '');
//check the value of $enddate and return true or false

Maybe this works:

[{"active:=":"1"},{"rating:>":"5"},{"OR:rating:=":"1"}]

Thanks for your support, but it didn’t work or I was doing something wrong: $scriptProperties was empty.

I solved this using a customized getImageList snippet and checked start/end date directly in the php code. Works fine and I’m happy with this solution.