wp_get_post_revision

函式
wp_get_post_revision ( $post, $output = OBJECT, $filter = 'raw' )
引數
  • (int|WP_Post) $post Post ID or post object.
    Required:
  • (string) $output Optional. The required return type. One of OBJECT, ARRAY_A, or ARRAY_N, which correspond to a WP_Post object, an associative array, or a numeric array, respectively. Default OBJECT.
    Required:
    Default: OBJECT
  • (string) $filter Optional sanitization filter. See sanitize_post().
    Required:
    Default: 'raw'
返回值
  • (WP_Post|array|null) WP_Post (or array) on success, or null on failure.
定義位置
相關方法
wp_get_post_revisionswp_get_post_revisions_urlwp_delete_post_revisionwp_save_post_revision_wp_put_post_revision
引入
2.6.0
棄用
-

wp_get_post_revision: 這個函式用來檢索一個文章的修訂版,由它的修訂ID來識別。它返回一個包含修訂資訊的陣列,包括文章內容和後設資料。

獲得一個文章的修訂版。

function wp_get_post_revision( &$post, $output = OBJECT, $filter = 'raw' ) {
	$revision = get_post( $post, OBJECT, $filter );

	if ( ! $revision ) {
		return $revision;
	}

	if ( 'revision' !== $revision->post_type ) {
		return null;
	}

	if ( OBJECT === $output ) {
		return $revision;
	} elseif ( ARRAY_A === $output ) {
		$_revision = get_object_vars( $revision );
		return $_revision;
	} elseif ( ARRAY_N === $output ) {
		$_revision = array_values( get_object_vars( $revision ) );
		return $_revision;
	}

	return $revision;
}

常見問題

FAQs
檢視更多 >