We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 17838
    • 82 Posts
    Today is hard day: I failed trying to open xPDO documentation page. Due to these circumstances I’m putting my problem here.

    The following code (modified from resource/search processor):

    		$c = $modx->newQuery('modResource');
    		
    		$where = array();
    		if (isset($_REQUEST['id']) && $_REQUEST['id'] != '') {
    		    $where['id'] = $_REQUEST['id'];
    		}
    		if (isset($_REQUEST['Szukaj']) && $_REQUEST['Szukaj'] != '') {
    		    $where['pagetitle:LIKE'] = "%$szukaj%";
    		    $where['longtitle:LIKE'] = "%$szukaj%";
    		    $where['content:LIKE'] = "%$szukaj%";
    		}
    		if (isset($_REQUEST['published']) && $_REQUEST['published'] == 'on') {
    		    $where['published'] = true;
    		}
    		if (isset($_REQUEST['unpublished']) && $_REQUEST['unpublished'] == 'on') {
    		    $where['published'] = false;
    		}
    		if (isset($_REQUEST['deleted']) && $_REQUEST['deleted'] == 'on') {
    		    $where['deleted'] = true;
    		}
    		if (isset($_REQUEST['undeleted']) && $_REQUEST['undeleted'] == 'on') {
    		    $where['deleted'] = false;
    		}
    			$where['searchable'] = 1;
    
    		$c->where($where);
    		$c->where(array('content:LIKE'=>'koncepcja'));
    		$c->sortby($_REQUEST['sort'],$_REQUEST['dir']);
    		$c->limit($_REQUEST['limit'],$_REQUEST['start']);


    produces following SQL query (ill just put a fragment which interests me the most):
    ... ` WHERE `modResource`.`pagetitle` LIKE '%koncepcja%' AND `modResource`.`longtitle` LIKE '%koncepcja%' AND `modResource`.`content` LIKE '%koncepcja%' AND `modResource`.`searchable` = 1 AND `modResource`.`OR content` LIKE '%koncepcja%' ORDER BY pagetitle ASC LIMIT 10


    It searches for word ’koncepcja’ in pagetitle, longtitle, content. But it uses AND so search must satisfy all 3 conditions.
    Instead of AND i would like to use OR.

    Is it possible to do it with such syntax or i should use xPDOCriteria or sth?

    --
    Regards
    MM
      • 22303 MODX Staff
      • 10,725 Posts
      The documentation is back up this AM, not sure why it started having problems yesterday but we’ll get it worked out...

      Anyway, to your question, you’ll want to call xPDOQuery->orCondition() on each group of conditions you want separated by an OR.