Site Speed WTF?!

Weekly Email

Please wait…


You have subscribed! A verification email will be sent to you.


SpeedGuard tracks Core Web Vitals from your WordPress. Check it out.

Bulk delete anything in WordPress: posts, comments, tags, revisions, and many more

Before you start:

  • Be careful and make a 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 tags with no posts

But probably with CPT!
Especially useful 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 that are not related to a 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 the WordPress blog totally, removing them from the 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?

Bulk delete anything in WordPress: posts, comments, tags, revisions, and many more

4 responses to “Bulk delete anything in WordPress: posts, comments, tags, revisions, and many more”

  1. Tariq Khan Avatar
    Tariq Khan

    Very Helpful. Thanks.

  2. Tariq Khan Avatar
    Tariq Khan

    Very Helpful. Thanks.

  3. Exalo Avatar

    Hi Sabrina,

    What if I want to use the function to delete empty terms from multiple taxonomies?
    Can I change this:
    $taxonomy_name = ‘city’;

    To this, for example:
    $taxonomy_name = ‘city’, ‘country’;

    to have those deleted as well? Adding to different functions with only the taxonomy changed leaves the site in error, you see.

    Thanks.

  4. Exalo Avatar

    Hi Sabrina,

    What if I want to use the function to delete empty terms from multiple taxonomies?
    Can I change this:
    $taxonomy_name = ‘city’;

    To this, for example:
    $taxonomy_name = ‘city’, ‘country’;

    to have those deleted as well? Adding to different functions with only the taxonomy changed leaves the site in error, you see.

    Thanks.

Leave a Reply

Your email address will not be published. Required fields are marked *