我需要以编程方式向DB中插入大约300篇文章。
通常我使用wp\\u insert\\u post每次处理一条记录来完成这项工作,但这次我认为它不能很好地处理数百行。
根据this, 在一个查询中插入多行可能会更快。所以,我想知道是否可以在一个查询中使用wp\\u insert\\u post。
对不起,我的英语不好。
我需要以编程方式向DB中插入大约300篇文章。
通常我使用wp\\u insert\\u post每次处理一条记录来完成这项工作,但这次我认为它不能很好地处理数百行。
根据this, 在一个查询中插入多行可能会更快。所以,我想知道是否可以在一个查询中使用wp\\u insert\\u post。
对不起,我的英语不好。
我建议使用wp\\u insert\\u post()并将文本文件放入CSV
CSV
Post Title,Post Content,
"title", "content",
"title", "content"...
PHP $path = "/posts.csv";
//require __DIR__ . "$path";
$file = fopen(__DIR__ . $path, \'r\');
while (($line = fgetcsv($file)) !== FALSE) {
//$line is an array of the csv elements
$post["id"] = wp_insert_post( array(
"post_title" => $line[0],
"post_author" => 1,
"post_content" => $line[1],
"post_type" => \'page\', //add post type
"post_status" => "publish"
));
}
fclose($file);
或者您可以执行SQL插入,看看-https://stackoverflow.com/questions/1670838/inserting-a-post-in-wordpress-using-mysql $sql = "INSERT INTO `wp_posts` (`ID`, `post_author`, `post_date`, `post_date_gmt`, `post_content`, `post_title`, `post_excerpt`, `post_status`, `comment_status`, `ping_status`, `post_password`, `post_name`, `to_ping`, `pinged`, `post_modified`, `post_modified_gmt`, `post_content_filtered`, `post_parent`, `guid`, `menu_order`, `post_type`, `post_mime_type`, `comment_count`) VALUES ";
$sql .= "(\' \',\'".$post_author."\',"."\'".$post_date."\',"."\'".$post_date_gmt."\',"."\'".$post_content."\',"."\'".$post_title."\',"."\'".$post_excerpt."\',"."\'".$post_status."\',"."\'".$comment_status."\',"."\'".$ping_status."\',"."\'".$posd_password."\',"."\'".$post_name."\',"."\'".$to_ping."\',"."\'".$pinged."\',"."\'".$post_modified."\',"."\'".$post_modified_gmt."\',"."\'".$post_content_filtered."\',"."\'".$post_parent."\',"."\'".$guid."\',"."\'".$menu_order."\',"."\'".$post_type."\',"."\'".$post_mime_type."\',"."\'".$comment_count."\'),";
$res = mysql_query($sql); if($res): print \'Successful Insert\'; else: print \'Unable to update table\'; endif;
你不能简单地替换所有wp_insert_post 做此函数没有运行单个SQL查询以插入到wp\\U帖子中。它还在wp\\U Posteta中添加内容,创建(如果需要)并将帖子链接到术语。因此,它可以运行5个或更多查询来创建一个帖子,这一切都取决于第一个添加到wp\\U帖子中的帖子,因为它必须从该查询中获取post\\u id,以便在其他Posteta和terms查询中使用。
如果只需将帖子添加到wp\\U帖子中(在帖子创建过程中不需要Posteta或链接到术语),可以通过PHPMyAdmin将CSV数据导入数据库,也可以创建一个包含多个insert语句的查询来添加多个记录。但是,根据我的经验,一次发送10个INSERT查询与每次发送10个请求和1个INSERT查询相比几乎没有什么好处。
我有一个WordPress博客,我在Dream Host上主持了几年了。最近(去年)我的网站经常宕机。通过Dream Host,我发现我正在使用我的CPU限制,他们正在杀死我的进程。这种情况过去一天发生两次,但我能把它减少到一周一次。我将我的缓存插件从W3 Total缓存交换到另一个缓存,并删除了一些插件。我有时还是会遇到问题。老实说,我是ASP。NET开发人员,所以我习惯于调试IDE和CMS应用程序中的工具。我如何才能弄清CPU问题的根源?有WordPress工具吗?此外,我的网站是为URL模式配置的h