Database Functionality Strange Person Web Developers Doctype Seo Search Engine Optimization blog Work Log Development Hourly Fee Variables Lt AJAX Working With Clients Information Technology Products WordPress box model Adminemail Hourly Rates Transitional Dtd Screen Resolutions Joomla Php Database Server Hostname Ideas Honesty Bandwidth Usage World Wide Web Husker Football rss Color Schemes SQL Page Password Web Applications 26b Import Functionality Tip Section 508 Video And Multimedia Firefox Colors Reference Multimedia Products Football Game Html Xmlns tips Time Web Sql Database Database Import Strategy Last Straw Lotus Notes Php Echo Microsoft Csv Laserjet 4100 Intranet Information Systems Css File Accurate Time Membership Login Forefront Tag Software Applications New Features Server Username CMS Dashboard Web Developer Email Account Rant Nuances Search Engine Optimization Membership Database Import mySQL Lot Internet Explorer 7 Design Borders Array Dynamic Css Div News Releases redirect Web Design Telegraph Sql Server Transparent Image Index Echo Config Php Search Google Capital Letters Mumbo Jumbo Cat Id Longest Time tricks Page Rank Web App View Source Indexing Services Blackberry Css Files XML Export Br App Branding Double Benefit Integrity Formatting Mobile Platforms Addressbook 2.1 Download Content Management System Login Php Asynchronous Javascript And Xml Gsa Gov database Term Relationships Headaches Php File Password Reset Php Variables W3c Gods Gift organization Select Name Cms Content PHP Tips Html Tag University Web System Administrator Deans List Google Telecommunications Products Div Id Social Networking Fellow Web Color Scheme encryption Insanity css SEO Internet Explorer Images Links Lotus Transition Habit develop Mysql Num Rows Email Settings Mysql Fetch Array free templates tools Traveling Php Password Free includes Ektron Free Download Marketing 2.6. 2.62 Nate Divs Variation Military Installation Gsa Federal Employees PHP Web Web Development Stylesheet Phpmyadmin Time Frame Full Time Templates steps Categories Address Book developer Portable Computers Area 51 Services Software Php Mysql
Database Functionality Strange Person Web Developers Doctype Seo Search Engine Optimization blog Work Log Development Hourly Fee Variables Lt AJAX Working With Clients Information Technology Products WordPress box model Adminemail Hourly Rates Transitional Dtd Screen Resolutions Joomla Php Database Server Hostname Ideas Honesty Bandwidth Usage World Wide Web Husker Football rss Color Schemes SQL Page Password Web Applications 26b Import Functionality Tip Section 508 Video And Multimedia Firefox Colors Reference Multimedia Products Football Game Html Xmlns tips Time Web Sql Database Database Import Strategy Last Straw Lotus Notes Php Echo Microsoft Csv Laserjet 4100 Intranet Information Systems Css File Accurate Time Membership Login Forefront Tag Software Applications New Features Server Username CMS Dashboard Web Developer Email Account Rant Nuances Search Engine Optimization Membership Database Import mySQL Lot Internet Explorer 7 Design Borders Array Dynamic Css Div News Releases redirect Web Design Telegraph Sql Server Transparent Image Index Echo Config Php Search Google Capital Letters Mumbo Jumbo Cat Id Longest Time tricks Page Rank Web App View Source Indexing Services Blackberry Css Files XML Export Br App Branding Double Benefit Integrity Formatting Mobile Platforms Addressbook 2.1 Download Content Management System Login Php Asynchronous Javascript And Xml Gsa Gov database Term Relationships Headaches Php File Password Reset Php Variables W3c Gods Gift organization Select Name Cms Content PHP Tips Html Tag University Web System Administrator Deans List Google Telecommunications Products Div Id Social Networking Fellow Web Color Scheme encryption Insanity css SEO Internet Explorer Images Links Lotus Transition Habit develop Mysql Num Rows Email Settings Mysql Fetch Array free templates tools Traveling Php Password Free includes Ektron Free Download Marketing 2.6. 2.62 Nate Divs Variation Military Installation Gsa Federal Employees PHP Web Web Development Stylesheet Phpmyadmin Time Frame Full Time Templates steps Categories Address Book developer Portable Computers Area 51 Services Software Php Mysql

Just today I was working on a clients WordPress install and ran into a considerable problem. I was trying to upgrade the version of WordPress from 2.1 to 2.6.2 and could imported the posts through the database import functionality (phpmyadmin). After doing the same with the comments, I thought all was set…Boy was I wrong…

The client had about 2,100 posts and everyone of them lot their category it was assigned to. If you run into this situation, simply do this and use my script and everything should be set without a problem!

1) Export wp_caterories and wp_post2cat from the old database through phpmyadmin (or similar)

2) Import these tables into your new WordPress install. These tables do not exist in the new WordPress, so nothing should be overwritten.

3) Backup and export your wp_term_relationships table from the new WordPress install (just in case).

4) Add your categories to your new WordPress install, making sure that the name remains absolutely identical. This means spaces and capital letters as well – You can always rename later.

5) Save the code blow as a PHP file and open it up in your browser.

<?php
global $adminemail, $baseurl;
//Enter your SQL Server HostName
$hostname=’localhost’;

//Enter the Username to login to the SQL Server
$username=’wordpress_dbname’;

//Enter the password to login to SQL Server – This is not seen in the code of a PHP page
$password=’wordpressdbpassword’;

//Enter the name of the db you are connecting to
$dbname=’wordpressdb’;

//Enter the email account of the system administrator
mysql_connect($hostname, $username, $password) or die(mysql_error()) ;
mysql_select_db($dbname) or die(mysql_error()) ;

$postfind = “SELECT * FROM wp_post2cat”;
$post2cat = mysql_query($postfind);
$num_rows = mysql_num_rows($post2cat);
echo “Found $num_rows in the query.<br>”;
while ($row = mysql_fetch_array($post2cat)) {
  $postid = $row[1];
  $catid=$row[2];
  $postfind5 = “SELECT * FROM `wp_categories` WHERE cat_ID=$catid”;
  $post2cat5 = mysql_query($postfind5);
  while ($row5 = mysql_fetch_array($post2cat5)) {
  $catname = $row5[1];
  }
  $postfind2 = “SELECT * FROM `wp_terms` WHERE name=’$catname’”;
  $post2cat2 = mysql_query($postfind2);
  while ($row2 = mysql_fetch_array($post2cat2)) {
   $termid = $row2[0];
   $postfind4 = “SELECT * FROM `wp_term_taxonomy` WHERE term_id=’$termid’”;
   $post2cat4 = mysql_query($postfind4);
   while ($row4 = mysql_fetch_array($post2cat4)) {
    $taxid = $row4[0];
    $insertpost = “INSERT INTO wp_term_relationships (object_id, term_taxonomy_id) VALUES (‘$postid’, ‘$taxid’)”;
    $insertresults = mysql_query($insertpost);
   }
  }
}
?>

 NOTE: You will need to change the settings in the above code to connect to your database. To find your settings, download wp-config.php from the root of your WordPress install and copy your info over.

6) After opening your php file of the above code, your imported posts should be categorized appropriately.

7) Be sure to delete your php file you saved from the code above.

 

You’re done! You can remov the wp_categories and wp_post2cat if you want to clean up your database, since these are not needed anymore.

Please note that this was 100% successful for me, but I cannot guarantee your success. Please do this at your own risk. I hope this post finds those who need it.

No comments yet.

Would you like to login?