KarthiKeyan

A Webmaster, Programmer, SEO Expert, Code Cracker, Student, Batsman, Social Activist & a cool guy :)

Nov

26

WordPress mass category killer

By Karthi

I faced a problem with my friend’s wordpress. He imported his blogger to wordpress, All blogger “tags” are converted into wordpress categories automatically. Basically, WordPress loads its menu widgets before than a post. So, his blog started showing thousands of categories.

He asked my help for clearing all categories. I just wrote a simple PHP script for that.

<?php
require(‘wp-config.php’);
$select = mysql_query(“SELECT * from `wp_term_taxonomy` where `taxonomy`=’category’ AND `term_id` != ’1′”);
$num = mysql_num_rows($select);
for($i=1;$i<=$num;$i++)
{
$row=mysql_fetch_array($select);
$termid=stripslashes($row['term_id']);
mysql_query(“DELETE FROM `wp_terms` WHERE `term_id`=’$termid’”);
mysql_query(“DELETE FROM `wp_term_taxonomy` WHERE `term_id`=’$termid’”);

}
echo(“Categories are deleted successfully!<br>”);
mysql_query(“UPDATE `wp_posts` SET `posts_category`=’1′”);
echo(“All posts are moved under \”Uncategorized\”!”);
?>

Execution Steps:

1. Save above code as catkiller.php

2. Upload it to your wordpress’s root folder.
ex: public_html/blog/catkiller.php
or
/httpdocs/catkiller.php

3. Pray your favorite God! and execute http://YourBlogurl/catkiller.php

And remember that, “catkiller” is not for your pussy cats ;)

I hope this may help someone.

Leave a comment

You must be logged in to post a comment.


Close
E-mail It