Skip to content

Instantly share code, notes, and snippets.

@sonicpunk
Created May 29, 2013 13:30
Show Gist options
  • Save sonicpunk/5670268 to your computer and use it in GitHub Desktop.
Save sonicpunk/5670268 to your computer and use it in GitHub Desktop.
MODX snippet: finds all resources with a specified template and writes a list of ids
<?php
$c = $modx->newQuery('modResource');
$resIds = array();
/* we only want published and undeleted resources */
$c->where(array(
'published' => true,
'deleted' => false,
'template'=>$templateID
));
$resources = $modx->getCollection('modResource',$c);
foreach ($resources as $resource) {
$resourceArray=$resource->toArray();
$resIds[]=$resourceArray['id'];
};
$resIds = array_values(array_unique($resIds)); // remove duplicated ids
//var_dump($resIds);
$lstIds = implode(',',$resIds);
return $lstIds;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment