我建议使用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;