Created
February 9, 2021 16:12
-
-
Save matdave/7cdb45c523fadedf881d4ecb18c4c2ed to your computer and use it in GitHub Desktop.
bulkChange Snippet for MODX
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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