Last active
April 27, 2021 17:49
-
-
Save Greg-Boggs/7d713c0443552d5b92bb835768fb0745 to your computer and use it in GitHub Desktop.
Delete some nodes with a drush command
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
| #!/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