我编写了以下函数,将计划发布的帖子更改为已发布的帖子(我有大约1000篇)。当我运行下面的代码时,日期会更改,但状态不会。。。
有人能解释一下这个问题吗?
This is the code I am using as of now:
/* CHANGE PENDING POSTS TO PUBLISHED POSTS */
function change_post_status($post_id, $status, $change_date){
$current_post[\'ID\'] = $post_id;
$current_post[\'post_status\'] = $status;
$current_post[\'post_date\'] = $change_date;
wp_update_post($current_post);
}
$args = array(
\'post_type\' => \'post\',
\'posts_per_page\' => -1,
\'post_status\' => \'future\',
\'orderby\' => \'date\',
\'order\' => \'ASC\',
);
$the_query = new WP_Query($args);
if ($the_query->have_posts()) {
$counter = 1;
while ($the_query->have_posts()) {
$the_query->the_post();
$pid = get_the_ID();
$newdate = date(\'Y-m-d H:i:s\', time() - (3600 * $counter));
change_post_status($pid, \'publish\', $newdate);
// echo \'TITLE: \'.get_the_title()
// .\' TIME:\'.date(\'Y-m-d H:i:s\', time()-(3600 * $counter)).\'<br/>\';
$counter++;
}
}
我对日期所做的所有“提前一小时”的事情都是可以的,“未来”的帖子实际上当前的日期是昨天,但在帖子列表中仍然有预定状态。