$myIds = $this->modx->getChildIds(2,2); $query = $this->modx->newQuery('modResource'); $query->select(array( 'modResource.id','modResource.pagetitle','tvv.contentid as tvvcontentid','tvv.value as example1','tvv2.value as example2','tv.name as tvname','tv2.name as tvname2','tv.id as tvid','tv2.id as tvid2' )); $query->leftJoin('modTemplateVarResource', 'tvv', array( 'tvv.contentid = modResource.id' )); $query->leftJoin('modTemplateVarResource', 'tvv2', array( 'tvv2.contentid = modResource.id' )); $query->leftJoin('modTemplateVar', 'tv', array('tv.id = tvv.tmplvarid','tv.name' => 'tv-eample1')); $query->leftJoin('modTemplateVar', 'tv2', array('tv2.id = tvv2.tmplvarid','tv2.name' => 'tv-example2')); $query->where(array('id:IN' => $myIds)); $query->groupby('id'); $items = $this->modx->getCollection('modResource', $query);
This question has been answered by multiple community members. See the first response.
$query->leftJoin('modTemplateVarResource', 'tv', array( 'modResource.id = tv.contentid', 'tv.tmplvarid' => '1' )); $query->leftJoin('modTemplateVarResource', 'tv2', array( 'modResource.id = mtvr2.contentid', 'tv2.tmplvarid' => '2' ));
LEFT JOIN `modx_site_tmplvar_contentvalues` `tvv` ON modResource.id = tvv.contentid and tvv.tmplvarid=(select id from `modx_site_tmplvars` where NAME = 'tv-eample1') LEFT JOIN `modx_site_tmplvar_contentvalues` `tvv2` ON modResource.id = tvv2.contentid and tvv2.tmplvarid=(select id from `modx_site_tmplvars` where NAME = 'tv-eample2')