我有一个内置laravel的博客,但我想将所有内容移动到wordpress中构建的现有博客,我已经尝试将数据库导出为CSV文件以导入我的wordpress数据库,但它不是以相同的表格格式,任何关于如何导入内容的想法
It is less likely to work the direct import since the table structures will be different. So what we can do is to
wpdb
query ( https://codex.wordpress.org/Class_Reference/wpdb ) wp_insert_post
( https://developer.wordpress.org/reference/functions/wp_insert_post/ ) You must take WordPress DB backup before doing this.
Sample code will be something like this.
$mydb = new wpdb('username','password','laravel_database','localhost');
$rows = $mydb->get_results("select title, content from laravle_blogs_table");
foreach ($rows as $obj) :
// Create post object
$my_post = array(
'post_title' => wp_strip_all_tags( $obj->title ),
'post_content' => $obj->content,
'post_status' => 'publish',
'post_author' => 1,
'post_category' => array( 8,39 )
);
// Insert the post into the database
wp_insert_post( $my_post );
endforeach;
You must change the field names as per your database.
This code can be put in any of the active theme files may be header.php
or footer.php
or other template and just load the page from your browser. If there are a huge number of posts put a limit to the select query and insert step by step.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.