We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 31640
    • 100 Posts
    I have a problem generating a correct where clause

    if(!empty($scriptProperties['worktype'])) {
    	$data['worktype:IN']  = explode(',', $scriptProperties['worktype']);
    }
    
    if(!empty($scriptProperties['salarylowerband'])) {
    	$data['salarymin:>=']  = explode(',', $scriptProperties['salarylowerband']);
    }
    
    if(!empty($scriptProperties['salaryupperband'])) {
    	$data['salarymax:<=']  = explode(',', $scriptProperties['salaryupperband']);
    }
    
    $data['publishdate:<'] = date("Y-m-d");
    $data['unpublishdate:IS'] = null;
    $data['OR:unpublishdate:>'] = date("Y-m-d");
    
    
    // Transform to json
    if(!empty($data)) {
     $str = json_encode($data);
    }
    
    return $str;
    


    It generates (pseudo code)
    worktype IN AND salarymin >= AND salarymax <= AND publishdate< AND unpublishdate IS null OR unpublishdate > date("Y-m-d")

    What i need is a where clause like
    worktype IN AND salarymin >= AND salarymax <= AND publishdate< AND (unpublishdate IS null OR unpublishdate > date("Y-m-d"))

    Everything is working fine except the part of the UNPUBLISHDATE. It needs to be in curly braces so it is threated together.

    Can somebody help me please...
      • 22827
      • 129 Posts

      From the query page, if you want paranthesis around part of the query, you would use an array within the array.

      http://rtfm.modx.com/xpdo/2.x/class-reference/xpdoquery