This question has been answered by BobRay. See the first response.
$docId = 12;
$docs = $modx->getCollection('modResource', array('parent' => $docId));
$count = count($docs);
foreach ($docs as $doc) {
$doc->remove();
}
return 'Removed ' . $count . ' resources.';
[[!MySnippet? &docId=12]]
/* the 12 here is a the default parent ID to use if no property is sent */
$docId = $modx->getOption('docId', $scriptProperties, 12, true);
$docs = $modx->getCollection('modResource', array('parent' => $docId));
$count = count($docs);
foreach ($docs as $doc) {
$doc->remove();
}
return 'Removed ' . $count . ' resources.';[[!MySnippet? &docId=12,22,34]]
$docIds = explode(',', $modx->getOption('docId', $scriptProperties, '', true));
$total = 0;
foreach ($docIds as $docId) {
$docs = $modx->getCollection('modResource', array('parent' => $docId));
$total += count($docs);
foreach ($docs as $doc) {
$doc->remove();
}
}
return 'Removed ' . $total . ' resources.';
If you have multiple parents to remove children of, you can do this:
[[!MySnippet? &docId=12,22,34]]