If you want to clean your Drupal installation and remove everything that belongs to a content type, it is better to use a Drupal query. You shouldn’t try to remove them directly from a custom SQL Query. Here is how you can use Drupal db_query function:
1 2 3 4 5 6 7 8 9 10 11 12 13 |
// Gather all the pivot content that might have been created while this // module was enabled. Simple selects still use db_query(). // http://api.drupal.org/api/function/db_query/7 $sql = 'SELECT nid FROM {node} n WHERE n.type = :type'; $result = db_query($sql, array(':type' => 'custom_type')); $nids = array(); foreach ($result as $row) { $nids[] = $row->nid; } // Delete all the nodes at once // http://api.drupal.org/api/function/node_delete_multiple/7 node_delete_multiple($nids); |
Another technique
1 2 3 4 5 6 7 8 |
$result = db_select('node', 'n') ->fields('n', array('nid')) ->condition('type', 'custom_type', '=') ->execute(); foreach ($result as $record) { node_delete($record->nid); } |
I would like to remove all nodes of a specific content type and also all the comments on that node.
There are over 20000 nodes of that content type and in total +900000 comments. Comments are also on other content types.
Is it a good idea to run another foreach-loop in the other foreach loop to remove all comments?
I guess it will be a very bad load for the server.
Or are there other alternatives?
Thanks,
Stijn
Normally if you run a node_delete(), Drupal will remove everything that is linked to this node, even comments.
Did you try with a test node containing one comment ?