the final touch

The one thing that was keeping me from recommending WP all-out to others was its import compatibility. Till now, I could import Blogger posts and make sure their comments were linked and counted. But I was not able to set their categories. I got this idea a few hours ago. Its my first PHP-MySQL code.

The MySQL query on lines 8-11 updates the post2cat table which holds the post-category linkages. The import script I am using somehow skips this detail. Once the posts have a legal category ID, it is a trivial matter to move them in the WP system.

// after initial install, this should be 3, check your wp_post2cat table, take last value + 1
$new_rel_id = 18;
// check the ID of the last imported post ID from admin interface
$last_post = 83;
// value of counter is the first imported post ID
for ( $counter = 3; $counter < = $last_post; $counter += 1)
        INSERT INTO wp_post2cat (rel_id, post_id, category_id)
        VALUES ('$new_rel_id', '$counter', '1' )
    ") or die(mysql_error());
    $new_rel_id += 1;

I will put up the full details of my WP install and an enhanced version of this code (two more queries to merge post authors and comment authors) on a static page later.