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:
返回值
  • (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_get_post_revision_versionwp_get_post_revisions_url_wp_post_revision_datawp_get_post_revisionwp_get_post_revisions
引入
6.1.0
棄用
-

wp_get_latest_revision_id_and_total_count: 這個函式檢索一個文章的最新修訂ID和總修訂數。它需要一個引數,就是文章的ID。它返回一個有兩個鍵的陣列,”latest_revision_id”和”total_revisions_count”。

返回一個文章的最新修訂ID和修訂次數。

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
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,
);
}
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, ); }
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,
	);
}

常見問題

FAQs
檢視更多 >