2011-12-21 76 views
0

我有一个包含以下表格的数据库:将数据从示例数据库类别表传输到wordpress

第一个表名:newsdetails。

列:id,description,cat_id

第二个表名:category。

列:id,name,parent_id。

现在我想将这些数据转移到wordpress数据库。

我知道:在wordpress中有一个wp_insert_post函数来在数据库中插入帖子。

有一个参数'post_category' => [ array(<category id>, <...>) ] //Add some categories.

此功能关联后,以一个特定的类别。

我现在拥有的是旧表格中的类别。即使我在这个参数中提供了这些类别,在wordpress数据库中也没有创建这样的类别。

如何根据现有类别表在wordpress中创建类别,以便我的新帖子现在将与新类别相关联?

回答

0

注册类别是这样的:

$category = array('cat_name' => 'My Category', 'category_description' => 'A Cool Category', 'category_nicename' => 'category-slug', 'category_parent' => ''); 

$cat_id = wp_insert_category($category, true); 

然后用$ CAT_ID该数组内,将工作。

更多信息在Wordpress Codex

相关问题