$currentID = $modx->resource->get('id');
$childIDs = $modx->getChildIds($currentID,1,array('context' => 'web'));
$childIDsString = implode(',', $childIDs);
$sql= "SELECT value FROM `modx_site_tmplvar_contentvalues` WHERE contentid IN ($childIDsString) AND tmplvarid = '18'";
mysql_query($sql);$criteria = $modx->newQuery('modTemplateVarResource');
$criteria->select(array($modx->getSelectColumns('modTemplateVarResource', 'modTemplateVarResource', '', array('id', 'value')))); //Primary key has to be selected
$criteria->where(array('contentid:IN' => $childIDs, //IN accepts array
'tmplvarid' => 18
));
$results = $modx->getCollection('modTemplateVarResource', $criteria);
return $results;
foreach($results as $data){
echo $data."<br>";
}foreach($results as $data)
{
$out[] = $data->value;
// OR
$out[] = $data->get('value');
}
return implode("\n", $out);
I have a resource with some childresources.
Now I want to grab all TV-Values from the tmplvarid 18, where the contentid is a child…
$currentID = $modx->resource->get('id'); $childIDs = $modx->getChildIds($currentID,1,array('context' => 'web')); $childIDsString = implode(',', $childIDs); $sql= "SELECT value FROM `modx_site_tmplvar_contentvalues` WHERE contentid IN ($childIDsString) AND tmplvarid = '18'"; mysql_query($sql);
$currentID = $modx->resource->get('id');
$childIDs = $modx->getChildIds($currentID,1,array('context' => 'web'));
/* build the query */
$query = $modx->newQuery('modTemplateVarResource', array('tmplvarid' => 18, 'contentid:IN' => $childIDs));
/* select just the value column */
$query->select($modx->getSelectColumns('modTemplateVarResource', '', '', array('value')));
$values = array();
/* prepare and execute a PDOStatement from the $query */
if ($query->prepare() && $query->stmt->execute()) {
/* use PDOStatement::fetchColumn() to get an array representing
the first column of the result set */
$values = $query->stmt->fetchColumn();
}