wp_get_post_autosave

函式
wp_get_post_autosave ( $post_id, $user_id = 0 )
引數
  • (int) $post_id The post ID.
    Required:
  • (int) $user_id Optional. The post author ID.
    Required:
返回值
  • (WP_Post|false) The autosaved data or false on failure or when no autosave exists.
定義位置
相關方法
wp_create_post_autosavewp_is_post_autosavewp_get_post_catswp_set_post_catswp_get_post_tags
引入
2.6.0
棄用
-

wp_get_post_autosave: 這個函式檢索一個文章的自動儲存版本。它接受一個文章的ID作為引數,並返回一個關於自動儲存修訂的資料陣列。

檢索指定文章的自動儲存資料。

返回一個文章物件,包含指定文章的自動儲存的資訊。如果傳遞了可選的$user_id,則返回該使用者的自動儲存資料,否則返回最新的自動儲存資料。

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
function wp_get_post_autosave( $post_id, $user_id = 0 ) {
global $wpdb;
$autosave_name = $post_id . '-autosave-v1';
$user_id_query = ( 0 !== $user_id ) ? "AND post_author = $user_id" : null;
// Construct the autosave query.
$autosave_query = "
SELECT *
FROM $wpdb->posts
WHERE post_parent = %d
AND post_type = 'revision'
AND post_status = 'inherit'
AND post_name = %s " . $user_id_query . '
ORDER BY post_date DESC
LIMIT 1';
$autosave = $wpdb->get_results(
$wpdb->prepare(
$autosave_query,
$post_id,
$autosave_name
)
);
if ( ! $autosave ) {
return false;
}
return get_post( $autosave[0] );
}
function wp_get_post_autosave( $post_id, $user_id = 0 ) { global $wpdb; $autosave_name = $post_id . '-autosave-v1'; $user_id_query = ( 0 !== $user_id ) ? "AND post_author = $user_id" : null; // Construct the autosave query. $autosave_query = " SELECT * FROM $wpdb->posts WHERE post_parent = %d AND post_type = 'revision' AND post_status = 'inherit' AND post_name = %s " . $user_id_query . ' ORDER BY post_date DESC LIMIT 1'; $autosave = $wpdb->get_results( $wpdb->prepare( $autosave_query, $post_id, $autosave_name ) ); if ( ! $autosave ) { return false; } return get_post( $autosave[0] ); }
function wp_get_post_autosave( $post_id, $user_id = 0 ) {
	global $wpdb;

	$autosave_name = $post_id . '-autosave-v1';
	$user_id_query = ( 0 !== $user_id ) ? "AND post_author = $user_id" : null;

	// Construct the autosave query.
	$autosave_query = "
		SELECT *
		FROM $wpdb->posts
		WHERE post_parent = %d
		AND post_type = 'revision'
		AND post_status = 'inherit'
		AND post_name   = %s " . $user_id_query . '
		ORDER BY post_date DESC
		LIMIT 1';

	$autosave = $wpdb->get_results(
		$wpdb->prepare(
			$autosave_query,
			$post_id,
			$autosave_name
		)
	);

	if ( ! $autosave ) {
		return false;
	}

	return get_post( $autosave[0] );
}

常見問題

FAQs
檢視更多 >