Created
April 17, 2021 12:44
-
-
Save Niloys7/e6e23323a1ff3e9d95d3357d925a431b to your computer and use it in GitHub Desktop.
//Delete all posts of a custom post type with its included post meta data and taxonomies by using wpdb
This file contains hidden or 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
function deletePostType($postType = ''){ | |
global $wpdb; | |
$result = $wpdb->query( | |
$wpdb->prepare(" | |
DELETE posts,pt,pm | |
FROM {$wpdb->prefix}posts posts | |
LEFT JOIN {$wpdb->prefix}term_relationships pt ON pt.object_id = posts.ID | |
LEFT JOIN {$wpdb->prefix}postmeta pm ON pm.post_id = posts.ID | |
WHERE posts.post_type = %s | |
", | |
$post_type | |
) | |
); | |
return $result!==false; | |
} | |
deletePostType('shop_deposit'); // add custom post type slug |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment