如何从Yii迁移到Woocommerce Wp,仍然保留旧的数据库(表,行) [英] How to migrate from Yii to Woocommerce Wp, Still keep to old database (table,rows)
问题描述
我有一个由yii框架编写的电子商务网站。我想重建与woocommerce wordpress。而我想保留旧的数据库(所有表,行)。但是wordpress以不同的方式(元数据)保存数据。
什么是这种情况下的解决方案,如何导入旧数据库和自定义字段与我的旧数据库相同? >
P / s:感谢对我的英语提前和遗憾。
不幸的是,没有简单的方法这样做:
首先,你必须使用 wp_insert_post
:
wp_insert_post($ post,$ wp_error);
http://codex.wordpress.org/Function_Reference/wp_insert_post
其次,您必须使用 add_post_meta
:
add_post_meta($ post_id,$ meta_key,$ meta_value,$ unique);
http://codex.wordpress.org/Function_Reference/add_post_meta
你最终得到的是这样的psuedo-code: / p>
$ yii_products =(从yii db获取产品,也许初始化一个新的PDO连接以连接到该数据库)
foreach($ yii_products as $ product)
{
//从yii中的现有数据类型创建post数组
$ post = array(
'title'=> $ product-> title,
...
);
//保存帖子
$ post_id = wp_insert_post($ post);
//添加元数据
// some_yii_field_name可以是'color','size'或任何woocommerce使用
add_post_meta($ post_id,'some_yii_field_name',$ product-> some_yii_field_name);
}
这将创建所有新的职位类型和适当的元数据。我会把这段代码放入一个只用于迁移的一次性插件。
祝你好运!
I have an e-commerce website writen by yii framework. I want to rebuild with woocommerce on wordpress. And I want to keep old database (all table, rows). But wordpress save data on a different way (metadata).
what is solution in this case, how to import old database and custom field same my old database?
P/s: thanks for advance and sorry about my english.
Unfortunately, there is no easy way to do this:
First, you must create the post using wp_insert_post
:
wp_insert_post( $post, $wp_error );
http://codex.wordpress.org/Function_Reference/wp_insert_post
Second, you must add the appropriate metadata using add_post_meta
:
add_post_meta($post_id, $meta_key, $meta_value, $unique);
http://codex.wordpress.org/Function_Reference/add_post_meta
What you end up with is something like this psuedo-code:
$yii_products = (get products from yii db. Perhaps init a new PDO connection to connect to that db.)
foreach($yii_products as $product)
{
//Create post array from existing datatype in yii
$post = array(
'title' => $product->title,
...
);
//Save post
$post_id = wp_insert_post($post);
//Add metadata
//some_yii_field_name could be 'color', 'size' or whatever woocommerce uses
add_post_meta($post_id, 'some_yii_field_name', $product->some_yii_field_name);
}
This will create all of your new post types and with the appropriate metadata. I would put this code into a throw-away plugin used only for migration.
Good luck!
这篇关于如何从Yii迁移到Woocommerce Wp,仍然保留旧的数据库(表,行)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!