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.
ExpressionEngine® Answers is a question and answer site for administrators, end users, developers and designers for ExpressionEngine® CMS. It only takes a minute to sign up.Sign up to join this community
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
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
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.
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. :)
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.