Upgrading / adding data from a B2 installation to a new WordPress installation

by oneafrikan on December 11, 2004

I’d been using B2 as the blog engine for my old website, and had been watching its progress to WordPress with much anticipation. That said, the problem I faced to upgrade was importing the old posts from the B2 database tables to the new WordPress database tables. In retrospect, it had been this challenge which kept me from getting my website up after a long hiatus offline.

So, I finally decided to look under the hood and see what I could do to get my posts transferred. My first attempts with scripts a while ago didn’t yield much, so I decided to try the MS Access route, rather than writing code. When you look at the columns in both B2 and WordPress there is a lot of similarity – basically WordPress has added a few things, but retained the naming conventions from B2, which makes using Access is really easy.

The jist of it is that you need to use an Append query in Access, matching the fields from the B2 tables to the WordPress tables. You also need to make sure that the id field is not updated so you retain the auto increment of the table and your historical posts (it doesn’t really matter that much, but I like to do it that way!)

Looking at the WordPress posts table (where all your posts are stored), you need to append your old data to the following columns:

post_author; post_date; post_date_gmt; post_content; post_title; post_category (I used the same date for post_date and post_date_gmt).

Once I’d run that query, I also ran an update query to update the comments column to make sure no comments could be posted by spammers (after two days of having the blog online, I’d had about 35 comments that were SPAM, all advertising gambling in one way or another) – setting it’s value from 1 to 0.

Once I’d done that, I thought I was home and dry – very easy to do and about 5 minute’s effort.

However, I reloaded my front page, and saw the following message:

Your search – Warning: Invalid argument supplied for foreach() in /home/httpd/vhosts/oneafrikan.com/httpdocs/wp-includes/template-functions-category.php on line 65

This was puzzling, so I did a search on the WordPress site, looking for the following:

Warning: Invalid argument supplied for foreach() wp-includes/template-functions-category.php on line 65

Which didn’t yield much…

So, after a bit of hair pulling, I went back to the source, looking through the template-functions-category.php code, and also looking at the database tables to see if I was missing anything. I noticed a table called post2category, had a look at it’s content, and realised that this was the table that was used to store whether a post was attached to more than one category. Clearly this was the problem, so I ran a quick append query, appending each post_id with its corresponding category_id, thus making sure that there were no errors in the output to the browser.

In doing this, I used MS Access to sort the tables out and phpMyadmin to export the new table data to a SQL file for uploading onto my server.
If you don’t already have, you would need to create a System DSN using an ODBC connection (the drivers for which you get from the mySQL website), so that MS Access can connect to the MySQL database.

And that’s it really. Bob’s your uncle.
If you’re on a *nix box, or you’re using a Mac (without MS Office for the Mac), my heart goes out to you…

Leave your comment

Required.

Required. Not published.

If you have one.

Protected with IP Blacklist CloudIP Blacklist Cloud