Truemag

  • Categories
    • Tips And Tricks
    • Internet
    • PHP
    • Javascript
    • CSharp
    • SQL Server
    • Linux
  • Lastest Videos
  • Our Demos
  • About
  • Contact
  • Home
  • Write With Us
  • Job Request
Home Tips And Tricks WordPress Delete Unused Post Tags By SQL Command

WordPress Delete Unused Post Tags By SQL Command

Few days ago, I deleted a lot of dump posts from one of my WordPress site. After that, I recognized there were ton of unused tags existed in the database. It’s wasting the server resources and slow down my site by retrieving/looping unnecessary records.

Therefore, I decided to clean up all unused tags to free up all related tables and increase the performance as well as page loading time.

SQL Commands to delete/remove all unused post tags in WordPress

You can use PhpMyAdmin or a particular SQL client to run these commands below. Again, please backup your database first and make sure you understand what are you doing.

DELETE FROM wp_terms WHERE term_id IN (SELECT term_id FROM wp_term_taxonomy WHERE COUNT = 0 );
DELETE FROM wp_term_taxonomy WHERE term_id NOT IN (SELECT term_id FROM wp_terms);
DELETE FROM wp_term_relationships WHERE term_taxonomy_id NOT IN (SELECT term_taxonomy_id FROM wp_term_taxonomy);

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

I worked on my side and significant reduce the database site. Remember to replace ‘wp_’ with your table_prefix.

After deleted all unused tags and its relationship, you should optimize those tables to reclaim the unused space and to defragment the data file. It’s very useful when you have deleted a large part of a table and definitely improve performance.

OPTIMIZE TABLE `wp_terms` , `wp_term_taxonomy` , `wp_term_relationships`;

OPTIMIZE TABLE `wp_terms` , `wp_term_taxonomy` , `wp_term_relationships`;

Good luck 🙂

Jun 29, 2011Hoan Huynh
Simple PHP Code Send EmailLinux Chmod Change Mode Directory Recursive
You Might Also Like:
  • How To Get WordPress Tags By Categories
  • Delete Bulk Draft And Trash WordPress Posts Includes All Tags, Comments, Meta Fields And Terms Associated
  • Delete WordPress Revision Posts, Its Relationships And Meta Data
  • Function Remove All HTML Tags In PHP
  • Auto Delete Old IIS Logs, FTP Logs, SMTP Logs In Windows
  • PHP Delete File Function
  • How To Delete Application In Facebook Developers
  • WordPress Check If Post Is In Category
  • Keep Posting When You’re On Vacation With WordPress Post TimeStamp
  • Delete, Shrink, Eliminate Transaction Log .LDF File
Hoan Huynh

Hoan Huynh is the founder and head of 4rapiddev.com. Reach him at [email protected]

9 years ago Tips And Tricksoptimize, performance, table_prefix, Wordpress, wp_term_relationships, wp_term_taxonomy, wp_terms507
0
GooglePlus
0
Facebook
0
Twitter
0
Digg
0
Delicious
0
Stumbleupon
0
Linkedin
0
Pinterest
Most Viewed
PHP Download Image Or File From URL
21,946 views
Notepad Plus Plus Compare Plugin
How To Install Compare Text Plugin In Notepad Plus Plus
19,784 views
Microsoft SQL Server 2008 Attach Remove Log
Delete, Shrink, Eliminate Transaction Log .LDF File
15,616 views
JQuery Allow only numeric characters or only alphabet characters in textbox
13,126 views
C# Read Json From URL And Parse/Deserialize Json
9,583 views
4 Rapid Development is a central page that is targeted at newbie and professional programmers, database administrators, system admin, web masters and bloggers.
Recent Posts
  • How to Write a Research Paper For Sale
  • Essay Writing – Some Useful Suggestions for Writing Urgent Essays
  • Essay Writing Service Tips For The Online Essay
  • Research Paper Writing Service
  • Annotated Bibliography Example – How it Can Help You
Categories
  • CSharp (45)
  • Facebook Graph API (19)
  • Google API (7)
  • Internet (87)
  • iPhone XCode (8)
  • Javascript (35)
  • Linux (28)
  • MySQL (16)
  • PHP (84)
  • Problem Issue Error (29)
  • Resources (32)
  • SQL Server (25)
  • Timeline (5)
  • Tips And Tricks (141)
  • Uncategorized (66)
Recommended
  • Custom Software Development Company
  • Online Useful Tools
  • Premium Themes
  • VPS
2014 © 4 Rapid Development