tools:db:wpexport
This is an old revision of the document!
WordPress exporter
Put this file in your blog root, say to /wpdump.php , then browse to http://yoursite/flatpress/wpdump.php
save the output as export.sql
from your browser window.
Import to the wordpress
table of your database using phpMyAdmin or any analogue tool (if your WP installation is not new, do a backup before!)
IMPORTANT! once you're done, delete it from the server!
Many thanks to the people who wrote the ruby script and thanks to native from SPBItalia for sharing.
- wpexport.php
<?php require_once('defaults.php'); require_once(INCLUDES_DIR.'includes.php'); if (function_exists('system_init')) { system_init(); } else { plugin_loadall(); } header('Content-Type: text/plain; charset=utf-8'); function toutf($str) { // comment this one and uncomment the following line if you're using SPB! return $str; //return mb_convert_encoding($str, 'UTF-8', 'ISO-8859-1'); } error_reporting(E_ALL); $WP_PREFIX = 'wp_'; $POSTID = 10; $COMMENTID = 10; $SQL_STRING = ''; $q = new FPDB_Query(array('start'=>0, 'count'=>-1, 'fullparse'=>true), null); while($q->hasMore()) { list($id, $e) = $q->getEntry(); $obj =& new comment_indexer($id); $clist = $obj->getList(); $ccount = count($clist); $date = date("Y-m-d H:i:s", $e['date']); $SQL_STRING = "INSERT INTO {$WP_PREFIX}posts (id, post_author, post_date, post_date_gmt, post_content, post_title, post_name, comment_count) "; $SQL_STRING .= "VALUES ({$POSTID}, 1, '{$date}', '{$date}', '" . addslashes(toutf(apply_filters('the_content', $e['content']))) . "', '" . addslashes(toutf($e['subject'])) ."', '"; $SQL_STRING .= sanitize_title($e['subject']) ."', {$ccount}); \n"; echo $SQL_STRING; foreach ($clist as $cid) { $c = comment_parse($id, $cid); $cdate = date("Y-m-d H:i:s", $c['date']); $SQL_STRING = "INSERT INTO {$WP_PREFIX}comments (comment_id, comment_post_id, comment_content, comment_author, comment_date, comment_date_gmt) "; $SQL_STRING .= "VALUES ($COMMENTID, $POSTID, '" . /* in questo particolare caso */ addslashes(toutf(apply_filters('the_content', $c['content']))). "', '"; $SQL_STRING .= addslashes(toutf($c['name'])) . "', '{$cdate}', '{$cdate}' ); \n"; echo $SQL_STRING; $COMMENTID++; } $POSTID++; } ?>
Added by marcoverga86 This new version works (tested) with WP 2.8. I've also added the SQL for the categories. Enjoy!
- wpexport_marcoverga86.php
<?php require_once('defaults.php'); require_once(INCLUDES_DIR.'includes.php'); require_once(SMARTY_DIR.'plugins/function.list_categories.php'); if (function_exists('system_init')) { system_init(); } else { plugin_loadall(); } header('Content-Type: text/plain; charset=utf-8'); function toutf($str) { // comment this one and uncomment the following line if you're using SPB! return $str; //return mb_convert_encoding($str, 'UTF-8', 'ISO-8859-1'); } error_reporting(E_ALL); $WP_PREFIX = 'wp_'; $POSTID = 10; $COMMENTID = 10; $CATID = 1; $SQL_STRING = ''; $cats=entry_categories_get(); foreach ($cats['defs'] as $v) { $SQL_STRING = ""; $SQL_STRING = "INSERT INTO {$WP_PREFIX}terms (term_id, name, slug, term_group) VALUES ( $CATID, '" . $v . "', '" . sanitize_title($v) . "', 0);" . "\n"; $CATID++; echo $SQL_STRING; } $q = new FPDB_Query(array('start'=>0, 'count'=>-1, 'fullparse'=>true), null); while($q->hasMore()) { list($id, $e) = $q->getEntry(); $obj =& new comment_indexer($id); $clist = $obj->getList(); $ccount = count($clist); $date = date("Y-m-d H:i:s", $e['date']); $SQL_STRING = "INSERT INTO {$WP_PREFIX}posts (post_content_filtered, pinged, to_ping, post_excerpt, id, post_author, post_date, post_date_gmt, post_content, post_title, post_name, comment_count) "; $SQL_STRING .= "VALUES ('', '', '','', {$POSTID}, 1, '{$date}', '{$date}', '" . addslashes(toutf(apply_filters('the_content', $e['content']))) . "', '" . addslashes(toutf($e['subject'])) ."', '"; $SQL_STRING .= sanitize_title($e['subject']) ."', {$ccount}); \n"; echo $SQL_STRING; foreach ($clist as $cid) { $c = comment_parse($id, $cid); $cdate = date("Y-m-d H:i:s", $c['date']); $SQL_STRING = "INSERT INTO {$WP_PREFIX}comments (comment_id, comment_post_id, comment_content, comment_author, comment_date, comment_date_gmt) "; $SQL_STRING .= "VALUES ($COMMENTID, $POSTID, '" . /* in questo particolare caso */ addslashes(toutf(apply_filters('the_content', $c['content']))). "', '"; $SQL_STRING .= addslashes(toutf($c['name'])) . "', '{$cdate}', '{$cdate}' ); \n"; echo $SQL_STRING; $COMMENTID++; } $POSTID++; } ?>
tools/db/wpexport.1577833379.txt.gz ยท Last modified: 2020/01/01 00:02 by arvid