Before you start:
- Be careful and make database backup before you start.
- All these functions can be fired by any hook, obviously. If you leave wp_head that I used in examples it’s fine. But be aware that it’s gonna be fired on each and every time any page of the website is accessed.
- Therefore, if you have a high-traffic website and large database to process this might cause a load on your server — consider another method to use. (to split it in chunks and to make sure it only fired once).
- Bulk delete tags in WordPress
- Delete all posts or custom post types in WordPress
- Delete all comments in WordPress
- What about attachments, images and media?
Bulk delete tags in WordPress
Delete tags with no posts
But probably with cpt!
especially usefull when you got some tags assigned to custom posts and regular posts as well and need to delete those which not assigned to regular posts
*The same way you can delete tags which are not related to specific cpt. Just replace
'post_type' => 'post' with your custom post type name
Delete empty tags / unused tags
which means neither post, nor custom posts are assigned to these tags
Bulk delete tags (absolutely all)
Delete empty taxonomy terms:
*mind to replace
$taxonomy_name = 'city'; with your taxonomy’s name
Delete all terms of certain taxonomy
whether they got posts or no
Delete all posts or custom post types in WordPress
These snippets will bulk delete all posts/custom posts/comments/revisions from wordpress blog totally, removing them from database. Proceed with caution.
Delete all posts:
Delete all custom posts:
*mind to change “book” to the custom post type name you want to bulk delete
Delete all post revisions:
Delete all comments in WordPress
Delete all spam comments:
Delete all comments:
What about attachments, images and media?
Check out this post for details: Delete media programmatically in WordPress: attachments, unattached images, 404, orphaned
You’ve made a backup, right?