Skip to content

Instantly share code, notes, and snippets.

@Greg-Boggs
Last active April 27, 2021 17:49
Show Gist options
  • Select an option

  • Save Greg-Boggs/7d713c0443552d5b92bb835768fb0745 to your computer and use it in GitHub Desktop.

Select an option

Save Greg-Boggs/7d713c0443552d5b92bb835768fb0745 to your computer and use it in GitHub Desktop.
Delete some nodes with a drush command
#!/usr/bin/env drush
//
// Usage: Edit the query as you need.
//
// drush scr --uri=events.lndo.site delete-nodes.php
//
// See `drush topic docs-scripts` for more information.
//
drush_print("Hello world!");
// Query all of the nids of a particular content type.
$nids = db_select('node', 'n')
->fields('n', array('nid'))
->condition('status', 0, '=')
->execute()
->fetchCol();
// Get all of the event nodes
$i = 0;
foreach ($nids as $n) {
node_delete($n);
echo'.';
$i++;
}
drush_print("Deleted " . $i . " nodes.");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment