2

数据库架构。

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

这个数据库经常被另一个 webapp 更新。

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

当我四处搜索时,我发现了 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 帖子中?

多谢

4

1 回答 1

1

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

于 2013-04-02T09:30:00.003 回答