【问题标题】:Error uploading posts to a Wordpress database?将帖子上传到 Wordpress 数据库时出错?
【发布时间】:2018-02-05 14:30:00
【问题描述】:

所以我有这个非 wordpress 数据库,我需要将所有帖子放入 Wordpress 数据库中,为此我使用此脚本但仅从 11231 上传 1037 行。

这是脚本。

<?php
  ini_set('max_execution_time', 300); 
  require("connect.php");
  $conn = mysqli_connect("127.0.0.1","root","psswd");
  mysqli_select_db($conn,"db_test");
  $results = mysqli_query($conn,"SELECT * FROM test");
  $i = 0;
  while ($row = mysqli_fetch_array($results,MYSQL_ASSOC)) {
  $post = array();
  $post['post_status'] = 'publish';
  $post['ID']=$row['idPost'];
  $post['post_date']=$row['date'];
  $post['post_date_gmt']=$row['date'];
  $post['post_content']=$row['body'];
  $post['post_title']=$row['title'];
  $posts[$i] = $post;
  $i++;
}
 mysqli_free_result($results);
 mysqli_close($conn);

 require('C:\xampp\htdocs\test\wordpress\wp-load.php');
 foreach ($posts as $post) {
 wp_insert_post($post);
 }
?>

它没有显示任何错误。

我尝试从 CMD、Firefox 和 Chrome 执行脚本。

这是我迄今为止尝试过的:

· 添加ini_set('max_execution_time', 300);.

· 在wp_insert_post()函数所在的地方添加set_time_limit(0);

· 更改 my.ini 中的 max_allowed_pa​​cket 大小。

如果我们不能完成这项工作,我认为我可以执行 INSERT TO,但这样就不会生成 URL。

谢谢。

【问题讨论】:

  • ini_set('max_execution_time', 300); 可能太短,无法导入所有帖子(您为每个帖子使用多个数据库连接)。尝试ini_set('max_execution_time', 30000); 或仅set_time_limit(0); 而不使用ini_set。但它可能不会改变你的php.ini 配置

标签: php mysql database wordpress


【解决方案1】:

尝试将第二个参数设置为 true wp_insert_post($post,true) 。您可以看到任何错误。遭遇 。

【讨论】:

    猜你喜欢
    • 2014-07-12
    • 1970-01-01
    • 2014-02-17
    • 2012-11-20
    • 1970-01-01
    • 1970-01-01
    • 2018-10-02
    • 2018-11-12
    • 1970-01-01
    相关资源
    最近更新 更多