5

What is the best way to delete every entry in a particular channel?

I'm talking thousands of entries, so checking each entry and clicking delete isn't going to work.
I also know you can't just delete rows from exp_channel_data.

4 Answers 4

11

Why not just delete the Channel?

8
  • That's what I do. Mar 22, 2013 at 22:01
  • This was my 1st thought too. But he said exp_channel_data and seemed ready to dive into the database. Mar 23, 2013 at 0:56
  • 2
    Yeah, but if he just does ex_channel_data all the titles will still be in the exp_channel_titles and other associated data. Better to copy the channel settings, then like Lisa and Justin said, delete the channel. It will get rid of everything that needs to go. Run optimize on the database tables. Then rebuild the channel. Unless the channel had like 50 fields, it's probably the quickest option as well. Mar 23, 2013 at 1:20
  • 1
    One should remember that there can be other data related to entries, stored in separate tables, like categories, tags, matrix records etc. So deleting a channel would be the right way.
    – Yuri Salimovskiy
    Mar 23, 2013 at 10:28
  • This seems like the best solution. Just confirming... deleting the channel actually deletes the entries? Mar 23, 2013 at 15:44
4

Best bet might be to go through the database tables and look for any entry_id fields. Those tables have foreign keys on entry_id (or just dependencies) and are where you need to track down loose ends.

For example, if you have comments enabled, you'll need to delete from exp_comments first:

Delete from exp_comments where entry_id in (Select entry_id from exp_channel_titles where channel_id = 22)

You can use that subselect in all your cleanup queries to make sure you match that original list. It's a bit more intuitive too.

exp_channel_data is the other half of your channel entries, so that should be cleaned up before exp_channel_titles.

Last step will be to clean up exp_channel_titles. That's where entries are established. You could have entries there without really having any exp_channel_data, if no channel field group was assigned.

1

So you want to delete all entries, but keep the channel itself, correct?

@Mark J. Reeves' solution is good if you feel comfortable running raw SQL commands, either through the control panel or from something like phpMySQL. Alas, I am not so adventurous/confident in my geek-fu levels. I would go to the Edit screen, select the channel you want to clean out, select "150 results" to see 150 results from that channel, per screen.

Then I'd select the checkbox in the top of the rightmost column (to select all 150), scroll down to the bottom of the Edit listing, select "Delete Selected", and hit the Submit button. Then repeat that process 10 times, to wipe out 1500 posts.

Note, however, that that is still not instant. You have to do that over and over until the channel is emptied - and if you've got 4K entries in the channel, that's a LOT of repeats. But it's much faster than selecting each one individually, and you don't need to worry about typing in the correct SQL command.

Edit: I guess you could call Mark's answer best-practices/fastest results, and mine the "training wheels" approach. :)

1

To delete all channel items but keep the channel itself (e.g. channel id may be hardcoded in some custom code or whatever), do from the admin panel:

The usual way is to select items page by page, click "delete", repeat for all pages. Works, but quite tedious especially for a lot of items.

To make it less tedious, in the chrome inspector tool, replace the value (not text) of "Show N results" select box to a bigger number, then select the item you just edited. Voila - more items are now displayed at once. Select them all and click "Delete" at the bottom of the page.

Processing will be slow but will work eventually, give it some time.

With a lot of items, it is possible to hit server's script execution time limits, or memory limits, reduce the entered number in this case. Reasonable amount is around 1000, but really depends on the server.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.