wp_get_latest_revision_id_and_total_count
函数
wp_get_latest_revision_id_and_total_count ( $post = 0 )
- 参数
-
-
(int|WP_Post)
$post
Optional. Post ID or WP_Post object. Default is global $post.- Required: 否
-
(int|WP_Post)
- 返回值
-
- (array|WP_Error) { Returns associative array with latest revision ID and total count, or a WP_Error if the post does not exist or revisions are not enabled. @type int $latest_id The latest revision post ID or 0 if no revisions exist. @type int $count The total count of revisions for the given post. }
- 定义位置
-
-
wp-includes/revision.php
, line 544
-
wp-includes/revision.php
- 引入
- 6.1.0
- 弃用
- –
Returns the latest revision ID and count of revisions for a post.
function wp_get_latest_revision_id_and_total_count( $post = 0 ) {
$post = get_post( $post );
if ( ! $post ) {
return new WP_Error( 'invalid_post', __( 'Invalid post.' ) );
}
if ( ! wp_revisions_enabled( $post ) ) {
return new WP_Error( 'revisions_not_enabled', __( 'Revisions not enabled.' ) );
}
$args = array(
'post_parent' => $post->ID,
'fields' => 'ids',
'post_type' => 'revision',
'post_status' => 'inherit',
'order' => 'DESC',
'orderby' => 'date ID',
'posts_per_page' => 1,
'ignore_sticky_posts' => true,
);
$revision_query = new WP_Query();
$revisions = $revision_query->query( $args );
if ( ! $revisions ) {
return array(
'latest_id' => 0,
'count' => 0,
);
}
return array(
'latest_id' => $revisions[0],
'count' => $revision_query->found_posts,
);
}
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。