Can anyone tell me how to delete a specific content type, like delete all pages at once or delete all of something all at once of a specific type?

I have a content type that i want to delete all of that content type.

Thanks.

Comments

ViTok’s picture

go to > "your-site.com/?q=admin/content/node" and than filter to content type and than select all to delete them.

sry for my bad english

nancydru’s picture

blavish’s picture

Thank you for the reply and help.

I only have one problem, I have 15000 pages i want to delete and if i do it that way it will take me hours, maybe days. I am looking for a quick way to do that.

Any ideas?

nancydru’s picture

Just create a little php page or story:

<?php
  node_type_delete('page');
?>

As soon as you submit it, Drupal will delete all 15,000 nodes of the 'page' type. Make sure this is really what you want. Shouldn't take very long at all.

Not to be tooting my own horn, but after doing something of this nature I would suggest using the Site documentation module to look for orphan terms and other problems that might happen. You'll probably also want to OPTIMIZE your node and node_revisions tables at least.

Nancy W.
Drupal Cookbook (for New Drupallers)
Adding Hidden Design or How To notes in your database

blavish’s picture

I did what you said but then it deleted my content type but all the pages is still there. Now there only shows 5 entries per page on /admin/content/node where i can select and delete that type.

You have any idea how i can make this to show more? like 200 or so?

Thanks for the help.

nancydru’s picture

Must have been a senior, blonde moment. I didn't give you the other part:

  $result = db_query('SELECT n.nid FROM {node} n WHERE type = \'%s\'', 'type');   /* <-- fill in type */
  while ($obj = db_fetch_object($result)) { node_delete($obj->nid); }

This is the code to actually delete the nodes (and node_revisions).

As far as what is showing on the content page, I have no idea unless you accidentally have a filter specified.

Nancy W.
Drupal Cookbook (for New Drupallers)
Adding Hidden Design or How To notes in your database

blavish’s picture

Do i paste that at the same place as the other code?

Thanks

nancydru’s picture

bls20’s picture

Thanks for that code, was super helpful!

bohz’s picture

[I'll need this too, one day or another]
thanks!

Peloose’s picture

I'm a newbie. Blavish same, I also delete 1000 nodes with a specific type. NancyDru, can you explain to me one by one ... Thanks

nancydru’s picture

Explain what?

Peloose’s picture

where I ty this code :

node_type_delete('whatevertype')

thanks ... ;)

nancydru’s picture

PHP code pretty much can only go into a module, PHP-format page, or PHP-format block. Note that enabling the PHP core module is required to put it in content, and can introduce security exposures. And, as always, try it on a test system first, and back up your database beforehand. There is no way to UNDO this, except reloading the database.

Peloose’s picture

Ok, I'll try ...

merryfknpoppins’s picture

Nancy,
It may have been a senior blonde moment posting the wrong solution.. I.e. instructing this guy to delete the content type and not the content, but the real "oops" moment was not going back and editing your post so that the next guy coming across it doesn't go off and delete several of his content types instead of the content contained in them. I should have known better.. but please, for the next guys sake... go edit that response.

nancydru’s picture

According to http://api.drupal.org/api/drupal/modules--node--node.module/function/nod..., the first thing that is done is db_query("DELETE FROM {node_type} WHERE type = '%s'", $type); which I apparently misread. My apologies. But I am not able to edit it. The error was corrected a bit farther down the thread.

mcfilms’s picture

You didn't read the full thread before doing any deleting? I always scan to the bottom.

A list of some of the Drupal sites I have designed and/or developed can be viewed at motioncity.com

aminlatif’s picture

For those who are interested, in drupal 7 you have to use this code instead:

<?php
$query = db_query('SELECT n.nid FROM {node} n WHERE n.type = :tp', array(':tp' => '######'));
foreach ($query as $n) {
    node_delete($n->nid);
}
?>
vali hutchison’s picture

Useful code snippet, thanks.