This script imports your entries from Textpattern into WordPress. It should be relatively painless, and we hope you're happy with the result.
To run this, you first need to edit this file (import-textpattern.php
) and enter your Textpattern database connection details. Let's check if the database connection information works...
Everything seems dandy so far, let's get started!
It looks like your database information is incorrect. Please re-edit this file and double-check all the settings.
First let's get posts and comments.
posts` ADD `post_name` VARCHAR(200) NOT NULL"; maybe_add_column($wpdb->posts, 'post_name', $query); // Create post_name field $connection = @mysql_connect($tp_database_host, $tp_database_username, $tp_database_password); $database = @mysql_select_db($tp_database_name); // For now we're going to give everything the same author and same category $author = $wpdb->get_var("SELECT ID FROM $wpdb->users WHERE user_level = 10 LIMIT 1"); $category = $wpdb->get_var("SELECT cat_ID FROM $wpdb->categories LIMIT 1"); $posts = mysql_query('SELECT * FROM textpattern', $connection); while ($post = mysql_fetch_array($posts)) { // ID, AuthorID, LastMod, LastModID, Posted, Title, Body, Body_html, Abstract, Category1, Category2, Annotate, AnnotateInvite, Status, Listing1, Listing2, Section $posted = $post['Posted']; // 20030216162119 $year = substr($posted,0,4); $month = substr($posted,4,2); $day = substr($posted,6,2); $hour = substr($posted,8,2); $minute = substr($posted,10,2); $second = substr($posted,12,2); $timestamp = mktime($hour, $minute, $second, $month, $day, $year); $posted = date('Y-m-d H:i:s', $timestamp); $content = $post['Body_html']; $title = $post['Title']; $post_name = sanitize_title($title); $wpdb->query("INSERT INTO $wpdb->posts (post_author, post_date, post_content, post_title, post_category, post_name, post_status) VALUES ('$author', '$posted', '$content', '$title', '$category', '$post_name', 'publish')"); // Get wordpress post id $wp_post_ID = $wpdb->get_var("SELECT ID FROM $wpdb->posts ORDER BY ID DESC LIMIT 1"); // Now let's insert comments if there are any for the TP post $tp_id = $post['ID']; $comments = mysql_query("SELECT * FROM txp_Discuss WHERE parentid = $tp_id"); if ($comments) { while($comment = mysql_fetch_object($comments)) { // discussid, parentid, name, email, web, ip, posted, message // For some reason here "posted" is a real MySQL date, so we don't have to do anything about it // comment_post_ID comment_author comment_author_email comment_author_url comment_author_IP comment_date comment_content comment_karma $wpdb->query("INSERT INTO $wpdb->comments (comment_post_ID, comment_author, comment_author_email, comment_author_url, comment_author_IP, comment_date, comment_content) VALUES ($wp_post_ID, '$comment->name', '$comment->email', '$comment->web', '$comment->ip', '$comment->posted', '$comment->message')"); } } } upgrade_all(); ?>All done. Wasn’t that fun? Have fun.