正如Rarst提到的,我必须使用wp_update_post()
, 但还有一个小把戏——一个人也必须设置edit_date = true
否则它的行为会很滑稽。最终代码如下所示:
function schedule() {
$postdate = date(\'2014-06-11 01:00:00\');
$postdate_gmt = date(\'2014-06-11 05:00:00\');
$post = array(
\'ID\' => 11,
\'post_status\' => \'future\',
\'post_type\' => \'post\',
\'post_author\' => \'1\',
\'ping_status\' => \'closed\',
\'to_ping\' => \'http://rpc.pingomatic.com/\',
\'post_date_gmt\' => $postdate_gmt,
\'post_date\' => $postdate,
\'edit_date\' => \'true\'
);
wp_update_post( $post, true );
}
add_action(\'wp_head\', \'schedule\');
下面介绍了如何使用文本文件处理许多帖子:
Text File:
postid,server_time,gmt_time
postid,server_time,gmt_time
postid,server_time,gmt_time
postid,server_time,gmt_time
...
功能:
function schedule() {
$fh = @fopen( dirname( __FILE__ ) . \'/schedule.txt\', \'r\' );
if ( $fh ) {
while ( ( $line = fgets( $fh ) ) !== false ) {
$ids = explode( \',\', $line );
array_walk( $ids, \'trim\' );
$postdate = date($ids[1]);
$postdate_gmt = date($ids[2]);
$post = array(
\'ID\' => $ids[0],
\'post_status\' => \'future\',
\'post_type\' => \'post\',
\'post_author\' => \'5\',
\'ping_status\' => \'closed\',
\'to_ping\' => \'http://rpc.pingomatic.com/\',
\'post_date_gmt\' => $postdate_gmt,
\'post_date\' => $postdate,
\'edit_date\' => \'true\'
);
wp_update_post( $post, true );
}
}
}
add_action(\'wp_head\', \'schedule\');
非常感谢在这篇文章和其他文章中提供帮助的所有人!