wordpress wp_insert_post花了太长时间

时间:2013-04-07 23:15:58

标签: php database wordpress

我正在使用一个简单的php文件发布到我的wordpress,到目前为止我有大约900个帖子,但我注意到发布的时间太长了!有时它甚至耗尽(30秒+)!这是我使用的代码。

 <?php
  require_once('./../wp-blog-header.php');
  require_once('./simple_html_dom.php');
  require_once('./../wp-admin/includes/taxonomy.php');

function postit($category,$date,$title,$content,$keys){
$cat=wp_create_category($category);
$post = array(
  'comment_status' => 'open',// 'closed' means no comments.
  'ping_status'    => 'open', // 'closed' means pingbacks or trackbacks turned off
  'post_author'    => '1', //The user ID number of the author.
  'post_category'  => array($cat), //post_category no longer exists, try wp_set_post_terms() for setting a post's categories
  'post_content'   => $content, //The full text of the post.
  'post_date'      => date('Y-m-d H:i:s',strtotime($date)), //The time post was made.
  'post_date_gmt'  => date('Y-m-d H:i:s',strtotime($date)), //The time post was made, in GMT.
  'post_status'    => 'publish', //Set the status of the new post.
  'post_title'     => $title, //The title of your post.
  'post_type'      => 'post', //You may want to insert a regular post, page, link, a menu item or some custom post type
  'tags_input'     => $keys,//For tags.
  'post_content_filtered' => '1',
  'filter' => '1'
);

remove_filter('content_save_pre', 'wp_filter_post_kses');
remove_filter('content_filtered_save_pre', 'wp_filter_post_kses');
$r=wp_insert_post( $post ,$wp_error);
add_filter('content_save_pre', 'wp_filter_post_kses');
add_filter('content_filtered_save_pre', 'wp_filter_post_kses');
return $r;
}

当我在探查器中运行时,

wp_create_category运行0.01秒。删除过滤器和wp_insert_post的部分占用了剩余的执行时间,剩下的代码为0.8秒。

任何人都有建议对此进行优化吗?

1 个答案:

答案 0 :(得分:2)

找到解决方案。是我的一个插件造成了这种延迟。一旦我禁用了所有插件,延迟就是goan!

我认为有些插件为wp_new_post添加了一个过滤器/钩子,并且该钩子导致了这个延迟问题。

面向未来的googlers。 只是禁用所有插件并尝试发布,如果问题是goan然后开始逐个启用它们,直到找到导致此问题的插件。

感谢大家的评论和帮助