从另一个自定义数据库导入到wordpress的帖子

时间:2013-04-02 09:26:21

标签: php mysql wordpress

数据库架构。

ID    title    keywords    category    body      time
1      XX      demo,tag      main      <html>    NOW()
2      YY      demo2,tag     main      <html>    NOW()

此数据库经常被其他网络应用程序更新。

我的问题是我如何发布创建一个自定义的php文件,可以处理从这个表发布到wordpress的新记录?

当我用Google搜索时,我发现wp_insert_post api,但他们提到如果它不在那里就不会创建类别。

  foreach($data as $db){
  $my_post = array();
  $my_post['post_title'] = $db->title;
  $my_post['post_content'] = $db->body;
  $my_post['post_status'] = 'publish';
  $my_post['post_author'] = 1;

  //$my_post['post_category'] = array(8,39);//how to fetch the category id !
  //$my_post['tags_input'] = explode(',',$db->keywords);///IS THIS CORRECT??

// Insert the post into the database
  wp_insert_post( $my_post );}

那么有人可以解释一下如何将数据库导出到带有类别的wordpress帖子(如果不存在则创建),标签,标题,时间日期和内容?

非常感谢

1 个答案:

答案 0 :(得分:1)

您可以使用wp_create_category创建类别 - 您的导入脚本应该分析源数据并在必要时创建类别

相关问题