wp_get_post_revisions

函式
wp_get_post_revisions ( $post = 0, $args = null )
引數
  • (int|WP_Post) $post Optional. Post ID or WP_Post object. Default is global `$post`.
    Required:
  • (array|null) $args Optional. Arguments for retrieving post revisions. Default null.
    Required:
    Default: null
返回值
  • (WP_Post[]|int[]) Array of revision objects or IDs, or an empty array if none.
相關
  • get_children()
定義位置
相關方法
wp_get_post_revisionwp_get_post_revisions_urlwp_list_post_revisionswp_delete_post_revision_wp_put_post_revision
引入
2.6.0
棄用
-

wp_get_post_revisions: 這個函式用來檢索一個特定文章的所有修訂版。它返回一個修訂物件的陣列,每個物件都包含有關修訂的資訊,包括文章內容和後設資料。

返回指定文章的所有修訂版。

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
function wp_get_post_revisions( $post = 0, $args = null ) {
$post = get_post( $post );
if ( ! $post || empty( $post->ID ) ) {
return array();
}
$defaults = array(
'order' => 'DESC',
'orderby' => 'date ID',
'check_enabled' => true,
);
$args = wp_parse_args( $args, $defaults );
if ( $args['check_enabled'] && ! wp_revisions_enabled( $post ) ) {
return array();
}
$args = array_merge(
$args,
array(
'post_parent' => $post->ID,
'post_type' => 'revision',
'post_status' => 'inherit',
)
);
$revisions = get_children( $args );
if ( ! $revisions ) {
return array();
}
return $revisions;
}
function wp_get_post_revisions( $post = 0, $args = null ) { $post = get_post( $post ); if ( ! $post || empty( $post->ID ) ) { return array(); } $defaults = array( 'order' => 'DESC', 'orderby' => 'date ID', 'check_enabled' => true, ); $args = wp_parse_args( $args, $defaults ); if ( $args['check_enabled'] && ! wp_revisions_enabled( $post ) ) { return array(); } $args = array_merge( $args, array( 'post_parent' => $post->ID, 'post_type' => 'revision', 'post_status' => 'inherit', ) ); $revisions = get_children( $args ); if ( ! $revisions ) { return array(); } return $revisions; }
function wp_get_post_revisions( $post = 0, $args = null ) {
	$post = get_post( $post );

	if ( ! $post || empty( $post->ID ) ) {
		return array();
	}

	$defaults = array(
		'order'         => 'DESC',
		'orderby'       => 'date ID',
		'check_enabled' => true,
	);
	$args     = wp_parse_args( $args, $defaults );

	if ( $args['check_enabled'] && ! wp_revisions_enabled( $post ) ) {
		return array();
	}

	$args = array_merge(
		$args,
		array(
			'post_parent' => $post->ID,
			'post_type'   => 'revision',
			'post_status' => 'inherit',
		)
	);

	$revisions = get_children( $args );

	if ( ! $revisions ) {
		return array();
	}

	return $revisions;
}

常見問題

FAQs
檢視更多 >