下面的代码可能需要一些调整,但这里的技巧是获取第一次修订的日期,并将其应用于正在发布的帖子:
add_action( \'transition_post_status\', function ( $new_status, $old_status, $post )
{
if ( $old_status == \'pending\' && $new_status == \'publish\'
&& $post->post_date_gmt == $post->post_modified_gmt) {
$revisions = wp_get_post_revisions($post->ID);
$oldest = NULL;
foreach($revisions as $revision){
$oldest = $revision->ID;
};
$previousdate = get_the_date( \'Y-m-d H:i:s\', $oldest );
wp_update_post(
array (
\'ID\' => $post->ID,
\'post_date\' => $previousdate,
\'post_date_gmt\' => get_gmt_from_date( $previousdate )
)
);
}
}, 10, 3 );