Php Wordpress:如何以编程方式为每天添加帖子?
我想知道是否有可能有一个脚本,自动创建每日帖子“从今天”到“结束日期”(在脚本中手动设置)。因此,在每次迭代中,post_日期将是$date+1day 首先,我不知道这个脚本是否必须在functions.php或elsswhere中执行 第二,我是php新手,所以我知道如何用“wp_insert_post”创建一篇文章,但我不知道如何在循环中插入它 寻求帮助,如果有人有想法。。。Php Wordpress:如何以编程方式为每天添加帖子?,php,wordpress,bulkinsert,Php,Wordpress,Bulkinsert,我想知道是否有可能有一个脚本,自动创建每日帖子“从今天”到“结束日期”(在脚本中手动设置)。因此,在每次迭代中,post_日期将是$date+1day 首先,我不知道这个脚本是否必须在functions.php或elsswhere中执行 第二,我是php新手,所以我知道如何用“wp_insert_post”创建一篇文章,但我不知道如何在循环中插入它 寻求帮助,如果有人有想法。。。 非常感谢是的,我们当然能做到。 从/wp includes/post.php开始,您可能需要遵循以下几个步骤: 将您
非常感谢是的,我们当然能做到。
从/wp includes/post.php开始,您可能需要遵循以下几个步骤:
function daily_post_article() {
$begin = new DateTime("2018-11-01");
$end = new DateTime("2018-12-15");
$interval = DateInterval::createFromDateString("1 day");
$period = new DatePeriod($begin, $interval, $end);
foreach ($period as $dt) {
$publishDate = $dt->format("Y-m-d");
$postTitle = "Daily Post Title => ".$publishDate;
if ( !get_page_by_title( $postTitle, "OBJECT", "post" ) ){
$args = array(
"post_title"=> "Daily Post Title => ".$publishDate,
"post_type"=>"post",
"post_date" => $publishDate,
"post_status"=>"future"
);
$time = strtotime( $postdate . " GMT" );
$post_id = wp_insert_post( $args );
wp_schedule_single_event( $time, "publish_future_post", array( $post_id ) );
}
}
}
add_action("wp", "daily_post_article");
非常感谢,但是我可以在没有CRON的情况下使用它吗?只需将脚本例外一次,并从“今天”到“结束日期”创建尽可能多的帖子。请将此代码添加到当前激活主题的functions.php文件中,如果您遇到任何问题,请告诉我。