我试图从外部的 php 文件 wp_ 插入_ post 。 如果没有循环, 此文件可以工作 。 我花了很长时间, 但我无法查找类似信息 。
<?php
require( wp-blog-header.php );
$tmpstr = array(
ID => 1,
post_title => $title,
post_content => $post content,
post_status => publish ,
post_author => 1 ,
post_type => $type
);
wp_insert_post($tmpstr);
?>`
然而,当我把一个环,
<?php
for ($i=0;$i<10,$i++) {
require( wp-blog-header.php );
$tmpstr = array(
ID => 1,
post_title => $title[$i],
post_content => $post content[$i],
post_status => publish ,
post_author => 1 ,
post_type => $type
);
wp_insert_post($tmpstr);
}
?>
It insert only 1 time into mysql database, then it stops I have tried changing the require( wp-blog-header.php ); to require( /path/to/wp-blog-header.php ); but it still does not solve my problem. If i comment out the wp_insert_post and require( wp-blog-header.php ); and add echo $post_content[$j];echo $post_title[$j]; all values are displayed correctly in my browser
Could anyone please help me to make it loop for 10 times, so that it can insert 10 entries? Thank you in advance!