Skip to content

Instantly share code, notes, and snippets.

@matdave
Created February 9, 2021 16:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save matdave/7cdb45c523fadedf881d4ecb18c4c2ed to your computer and use it in GitHub Desktop.
Save matdave/7cdb45c523fadedf881d4ecb18c4c2ed to your computer and use it in GitHub Desktop.
bulkChange Snippet for MODX
<?php
// Choose the Parent ID for the bulk changes
$parent = 12393;
// Set how deep we want to search into sub-pages
$depth = 3;
// Grab all the IDs
$children = $modx->getChildIds($parent, $depth, array('context' => 'web'));
if(!empty($children)){
// load all child IDs as resources
$c = $modx->newQuery('modResource');
$c->where(array('id:IN'=>$children));
$collection = $modx->getCollection('modResource', $c);
if(!empty($collection)){
foreach($collection as $resource){
// Make the change we want
$resource->set('searchable', 0);
// Check if the change was successful
if(!$resource->save()){
echo "Unable to save resource $resource->id <br/>";
}
}
}else{
echo "No resources match criteria!";
}
}else{
echo "No child resources found!";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment