Back to Top

How to Delete Taxonomies from database in WordPress

To Delete Taxonomies from database in wordpess

Basically, Latest version of WordPress has 2 categories by default

1. Tags
2. categories.

Categories and tags are ways to organize and find posts within a blog and across blogs. Categories are like topics whereas tags are more like keywords.

Few days back my friend asked me, How can I delete terms from WordPress.yes, You can delete manually from WordPress admin panel but when you have a lot of terms in hundreds or thousands of value then it takes a lot of time.

As a developer, manually delete which is not the good way so you need to apply query which can delete the terms from the database.

So I have written one script to delete terms/taxonomies from database, just a few minutes and your all taxonomies removed from database like Magic 🙂

You need to create one custom file and put it into WordPress root folder. place below codes into it.

Here is the code for that.Let’s dive into it.

NOTE:Make Sure You Have the backup of the entire database so that you can get back to a known state if things go wrong.

//include file

//Query Code
$results= $wpdb->get_results("select * from {$wpdb->prefix}term_taxonomy where taxonomy LIKE  'post_tag'", ARRAY_A );

foreach ($results as $row){ 	

         	$wpdb->query("delete from {$wpdb->prefix}terms where term_id =  '".$row['term_id']."'") ;

	        $wpdb->query("delete from {$wpdb->prefix}term_relationships where term_taxonomy_id = '".$row['term_taxonomy_id']."'");	

$wpdb->query("delete from {$wpdb->prefix}term_taxonomy where taxonomy LIKE 'post_tag'");

//if translation plugin installed into wordpress,apply below query
$wpdb->query("delete from {$wpdb->prefix}icl_translations where element_type LIKE 'tax_post_tag'");	

Copy above code and place it.That’s it you’re done,I have tested it with latest version of wordpress 3.5.1 too.

Thank you for reading.Feel free to share your thoughts! Don’t Forget to Follow us on Twitter or Subscribe us to Get the Latest Updates.

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Most Popular Posts

What are Lambdas and Closures in PHP?

Posted on 1 year ago


How to set 301 Redirection in PHP

Posted on 4 years ago


What’s New in Docker 1.12

Posted on 2 years ago