Jump to main content Jump to doc navigation


Add an OR condition to the WHERE statement in the query.


API Docs: xPDOQuery::orCondition()

void orCondition ( $conditions, [ $binding = null], [ $group = 0])


Grab all boxes with width 12 or 14.

$query = $xpdo->newQuery('Box');
   'width' => 14,
   'width' => 12,
$boxes = $xpdo->getCollection('Box',$query);


The order you call the functions is important! The orCondition must come after the where method has been used.

Another Example

Here's a more familiar example used to retrieve pages when they've got publish/unpublish dates set. This demonstrates an alternative syntax for an or condition. Normally, each place in the array supplied to the where method is joined together by a SQL "AND", but you can use the "OR" prefix on your column names to specify how groups of terms are joined together.

In the following example, a page must be published (1), and the pub_date must be either zero OR less than or equal to the current timestamp. The unpub_date must be either zero OR greater than current timestamp.

$criteria = $modx->newQuery('modResource');
        'published' => 1,
                        'pub_date' => 0,
                        'OR:pub_date:<=' => time(),
                        'unpub_date' => 0,
                        'OR:unpub_date:>' => time(),

Example With Joined Tables

Your filter parameters can reference fields in other tables.

$query = $modx->newQuery('modUser');
   'modUser.username' => $email,
   'Profile.email' => $email,
$user = $modx->getObject('modUser', $query);

The filter parameters may use the class name (as in modUser above) or the alias (as the Profile above).

See Also

Support the team building MODX with a monthly donation.

The budget raised through OpenCollective is transparent, including payouts, and any contributor can apply to be paid for their work on MODX.



$0 per month—let's make that $500!

Learn more