MT | ECP | Quick way to delete all recurrences of an event
/*
This SQL Query will delete all recurrences of an event, while preserving the
original event. It can delete many thousands of recurrences per second on most
servers.
The query and steps below is modified version of that in this tutorial:
http://wpguru.co.uk/2013/02/how-to-bulk-delete-posts-in-wordpress-with-mysql/
It is recommended that you read the source article above before proceeding.
Step 1) Grab the "post_parent" ID for your recurring series of events. Navigate
to one of the recurrences in your WP Admin and click Edit Series. This will take
you to a URL like example.com/wp-admin/post.php?post=140&action=edit Grab the
post ID from this URL, in this case it’s 140.
Step 2) As the article says it’s first a good idea to preview the posts you are
going to delete before deleting them. Swap out the X at the bottom of the
following query with the post ID you just grabbed, in the case above we would
make the bottom line "WHERE a.post_parent = 140" Now run the query. The results
should be many thousands of posts all with the same title, your recurring event.
SELECT *
FROM wp_posts a
LEFT JOIN wp_term_relationships b ON ( a.ID = b.object_id )
LEFT JOIN wp_postmeta c ON ( a.ID = c.post_id )
LEFT JOIN wp_term_taxonomy d ON ( d.term_taxonomy_id = b.term_taxonomy_id )
LEFT JOIN wp_terms e ON ( e.term_id = d.term_id )
WHERE a.post_parent = x
Step 3) Now run the below query, be sure to once again swap out the post_parent
ID at the bottom for the ID you grabbed earlier.
Step 4) The original event which spawned the series still exists in your
WP-Admin. If you would like to delete it find it, click Trash Series, and you
are done. If you wish to instead edit its recurring rules click Edit Series and
make your modifications.
*/
delete a,b,c,d
FROM wp_posts a
LEFT JOIN wp_term_relationships b ON ( a.ID = b.object_id )
LEFT JOIN wp_postmeta c ON ( a.ID = c.post_id )
LEFT JOIN wp_term_taxonomy d ON ( d.term_taxonomy_id = b.term_taxonomy_id )
LEFT JOIN wp_terms e ON ( e.term_id = d.term_id )
WHERE a.post_parent = x