• How To?
  • Tips ‘n Tricks
  • WordPress
  • Snippets
  • Software
    • Browsers
    • Downloads
  • Web
  • Tools
    • Character Counter
    • chmod Calculator
    • Entities Encoder
    • Live HTML Editor
    • My IP
  • Contact
Twitter Facebook Google+ RSS
You are here: SumTips » Snippets » WordPress Snippets » Search and Delete Unused Post Tags in WordPress

Search and Delete Unused Post Tags in WordPress

Posted on November 17, 2011 by Renji | Short URL: http://sumtips.com/?p=5931

Here are three SQL queries to find and safely delete all unused tags from your WordPress blog database.

The below command will show you all the unused tags in the database.

SELECT *
FROM wp_terms wterms INNER JOIN wp_term_taxonomy wttax ON wterms.term_id = wttax.term_id
WHERE wttax.taxonomy =  'post_tag' AND wttax.count =0;

Remember to change the ‘wp_’ prefix to the one in your installation.

Now that you know which are the unused tags, you can search and delete them from your dashboard or simply run the below commands to delete them all at once.

DELETE FROM wp_terms WHERE term_id IN (SELECT term_id FROM wp_term_taxonomy WHERE count = 0 );
DELETE FROM wp_term_relationships WHERE term_taxonomy_id not IN (SELECT term_taxonomy_id FROM wp_term_taxonomy);

Tweet

Related posts:

  • Set Different Post Templates Based on ID, Tag and Category in WordPress
  • Add, Delete and Edit Custom Fields in WordPress
  • Select and Delete Multiple Tweets from your Twitter Account
  • Delete Akismet and Spam Comments Metadata
  • Change "Enter title here" text for Post, Page and Custom Post Type in WordPress
Categories: WordPress Snippets
Display Simple Maintenance Mode Message to Non-Admins
Automatically Add Attributes to All Images in WordPress Posts

One Response to “Search and Delete Unused Post Tags in WordPress”

  1. How to Mass Delete Unused Tags in WordPress says:
    June 2, 2012 at 3:32 PM

    [...] crashes. Delete Unused WordPress Tags [SQL Query]Below is a small but powerful SQL query (from Sumtips) which will delete all the unused tags from your WordPress database.DELETE FROM wp_terms WHERE [...]

  • Get Updates via Email

  • Recent Posts

    • CMS2CMS: Migrate Site from Drupal or Joomla to WordPress
    • WordPress: Add Preview Button in Distraction Free Writing
    • How to Activate or Deactivate Individual Jetpack Modules
    • Windows 8: Auto Update Defender with Windows Update Disabled
    • Automatically Start and Close Programs at Specific Time
    • How to Copy Code from Notepad++ with Syntax Highlighting
  • Random Posts

    • Paper Plus
    • Docs Gets Search Improvement and PDF Support
    • Samsung Galaxy S2 Specifications and Picture
    • Scooby Doo Solves Mystery for Google
    • Control Windows Volume With Keyboard Shortcuts
    • Windows 8: Backup Modern UI Apps Data Offline, & Restore Easily
  • Categories

    • Blogging
    • Games
    • Google
    • How To?
    • Linux
    • Microsoft
      • Windows
    • Miscellaneous
    • Phone
    • Snippets
      • AutoHotkey Snippets
      • CSS Snippets
      • htaccess Snippets
      • JavaScript Snippets
      • PowerShell Snippets
      • WordPress Snippets
    • Social
    • Software
      • Browsers
    • Tips 'n Tricks
    • Wallpapers
    • Web
© SumTips. Contact | Sitemap | Privacy Policy