检索指定帖子的自动保存数据。
原型
wp_get_post_autosave( int $post_id, int $user_id )
描述
返回一个post对象,其中包含为指定帖子自动保存的信息。如果传递了可选的$ user_id,则返回该用户的自动保存,否则返回最新的自动保存。
参数
$post_id
(int)
(Required)
帖子ID。
$user_id
(int)
(Optional)
帖子作者ID。
返回值
(WP_Post|false)
自动保存的数据或失败时或不存在自动保存时为false。
源文件
路径:wp-includes/revision.php
<?php
...
function wp_get_post_autosave( $post_id, $user_id = 0 ) {
$revisions = wp_get_post_revisions( $post_id, array( 'check_enabled' => false ) );
foreach ( $revisions as $revision ) {
if ( false !== strpos( $revision->post_name, "{$post_id}-autosave" ) ) {
if ( $user_id && $user_id != $revision->post_author )
continue;
return $revision;
}
}
return false;
}
...
?>
其他
英文文档:https://developer.wordpress.org/reference/functions/wp_get_post_autosave/