ID}", $b2db))->commentCount; // // WP category ID // $b2CatName = mysql_fetch_object(mysql_query("SELECT cat_name FROM `evo_categories` WHERE cat_ID = {$b2Post->post_category}", $b2db))->cat_name; $wpCatId = mysql_fetch_object(mysql_query("SELECT term_id FROM `wp_terms` WHERE name = '{$b2CatName}'", $wpdb))->term_id; // // get WP user ID // $b2UserNick = mysql_fetch_object(mysql_query("SELECT user_nickname FROM `evo_users` WHERE ID = {$b2Post->post_author}", $b2db))->user_nickname; $wpUserId = mysql_fetch_object(mysql_query("SELECT ID FROM `wp_users` WHERE user_nicename = '$b2UserNick'", $wpdb))->ID; // // escape all strings // foreach($b2Post as $key => $val) { $b2Post->$key = mysql_escape_string($val); } // // convert to utf-8 // $b2Post->post_content = mb_convert_encoding($b2Post->post_content, 'UTF-8'); if (empty($b2Post->post_title)) { $b2Post->post_title = $b2Post->post_urltitle; } // // post status // $wpPostStatus = 'publish'; if ($b2Post->post_status == 'private') { $wpPostStatus = 'private'; } // // add post // $insertQuery = "INSERT INTO wp_posts (ID, post_author, post_date, post_date_gmt, post_modified_gmt, post_modified, post_content, post_title, post_category, post_status, post_name, comment_count) VALUES ('{$b2Post->ID}', '$wpUserId', '{$b2Post->post_issue_date}', '{$b2Post->post_issue_date}', '{$b2Post->post_mod_date}', '{$b2Post->post_mod_date}', '{$b2Post->post_content}', '{$b2Post->post_title}', '$wpCatId', '$wpPostStatus', '{$b2Post->post_urltitle}', '{$commentCount}')"; mysql_query($insertQuery, $wpdb); $wpPostId = mysql_insert_id(); if(mysql_error($wpdb)) { print "ERROR: " . mysql_error($wpdb) . "\n"; } // // wp post status // if ($b2Post->post_status == 'private') { $timeArray = explode(" ", microtime()); $timeSince1970 = $timeArray[1]; mysql_query("INSERT INTO wp_postmeta (post_id, meta_key, meta_value) VALUES ($wpPostId, '_edit_lock', $timeSince1970)", $wpdb); mysql_query("INSERT INTO wp_postmeta (post_id, meta_key, meta_value) VALUES ($wpPostId, '_edit_last', 2)", $wpdb); } // // insert term (category) relationship // mysql_query("INSERT INTO wp_term_relationships (object_id, term_taxonomy_id) VALUES ($wpPostId, $wpCatId)", $wpdb); print "Imported: {$b2Post->post_title} ({$b2Post->post_urltitle})\n"; } // // Comments // print "Migrating Comments\n\n"; $query = mysql_query(" SELECT comment_post_ID, comment_author, comment_author_email, comment_author_url, comment_author_IP, comment_date, comment_content, comment_karma FROM evo_comments", $b2db); while($b2comment = mysql_fetch_object($query)) { // // escape all strings // foreach($b2comment as $key => $val) { $b2comment->$key = mysql_escape_string($val); } $b2comment->comment_content = mb_convert_encoding($b2comment->comment_content, 'UTF-8'); $insertQuery = "INSERT INTO wp_comments (comment_post_ID, comment_author, comment_author_email, comment_author_url, comment_author_IP, comment_date, comment_content, comment_karma) VALUES ('{$b2comment->comment_post_ID}', '{$b2comment->comment_author}', '{$b2comment->comment_author_email}', '{$b2comment->comment_author_url}', '{$b2comment->comment_author_IP}', '{$b2comment->comment_date}', '{$b2comment->comment_content}', '{$b2comment->comment_karma}')"; mysql_query($insertQuery, $wpdb); } print 'Done!'; ?>