Jump to main content Jump to doc navigation


Other versions: 3.x — Found a problem? Please edit this page or report an issue.


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


API Docs: http://api.modx.com/revolution/2.2/db_core_xpdo_om_xpdoquery.class.html#\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);

Warning 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