Created
September 29, 2017 16:01
-
-
Save rajitha-bandara/195c9920b67c1c543592176b1411bbf0 to your computer and use it in GitHub Desktop.
WordPress Bulk Delete - WooCommerce Products
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require_once( 'wp-load.php' ); | |
global $wpdb; | |
$sql_1 = "DELETE FROM ".$wpdb->prefix."term_relationships WHERE object_id IN (SELECT ID FROM ".$wpdb->prefix."posts WHERE post_type = 'product');"; | |
$sql_2 = "DELETE FROM ".$wpdb->prefix."postmeta WHERE post_id IN (SELECT ID FROM ".$wpdb->prefix."posts WHERE post_type = 'product');"; | |
$sql_3 = "DELETE FROM ".$wpdb->prefix."posts WHERE post_type = 'product';"; | |
$sql_4 = "DELETE relations.*, taxes.*, terms.* | |
FROM ".$wpdb->prefix."term_relationships AS relations | |
INNER JOIN ".$wpdb->prefix."term_taxonomy AS taxes | |
ON relations.term_taxonomy_id=taxes.term_taxonomy_id | |
INNER JOIN ".$wpdb->prefix."terms AS terms | |
ON taxes.term_id=terms.term_id | |
WHERE object_id IN (SELECT ID FROM ".$wpdb->prefix."posts WHERE post_type='product');"; | |
try{ | |
$wpdb->query($sql_1); | |
$wpdb->query($sql_2); | |
$wpdb->query($sql_3); | |
$wpdb->query($sql_4); | |
}catch(Exception $e){} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment