这有点“骇客”,但当你打电话时get_permalink
并且,您需要永久链接作为草稿,提供post对象的克隆,并填写详细信息:
global $post;
if ( in_array( $post->post_status, array( \'draft\', \'pending\', \'auto-draft\' ) ) ) {
$my_post = clone $post;
$my_post->post_status = \'publish\';
$my_post->post_name = sanitize_title(
$my_post->post_name ? $my_post->post_name : $my_post->post_title,
$my_post->ID
);
$permalink = get_permalink( $my_post );
} else {
$permalink = get_permalink();
}