Skip to content

Commit

Permalink
improve query; remove meta first and then posts (only subc)
Browse files Browse the repository at this point in the history
  • Loading branch information
faisal-alvi committed Jul 25, 2024
1 parent 2506645 commit 45786f1
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions uninstall.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,11 @@ function dt_delete_data() {
// Remove transients.
$wpdb->query( "DELETE FROM $wpdb->options WHERE option_name LIKE '_transient\_dt\_%';" );

// Delete subscription data from the post and post meta tables.
// Delete post meta entries where the post type is 'dt_subscription'
$wpdb->query( "DELETE meta FROM $wpdb->postmeta meta LEFT JOIN $wpdb->posts posts ON posts.ID = meta.post_id WHERE posts.post_type IN ( 'dt_subscription' );" );

// Delete posts of type 'dt_subscription'
$wpdb->query( "DELETE FROM $wpdb->posts WHERE post_type IN ( 'dt_subscription' );" );
$wpdb->query( "DELETE meta FROM $wpdb->postmeta meta LEFT JOIN $wpdb->posts posts ON posts.ID = meta.post_id WHERE posts.ID IS NULL;" );

// Clear cache.
wp_cache_set_posts_last_changed();
Expand Down

0 comments on commit 45786f1

Please sign in to comment.