setup_postdata

函式
setup_postdata ( $post )
引數
  • (WP_Post|object|int) $post WP_Post instance or Post ID/object.
    Required:
返回值
  • (bool) True when finished.
定義位置
相關方法
get_postdatasetup_userdatawp_reset_postdatagenerate_postdataset_post_format
引入
1.5.0
棄用
-

setup_postdata: 這是一個WordPress的函式,在一個迴圈中用當前文章的資料設定全域性$post變數。它通常用於在迴圈中訪問文章資料,如標題、內容和自定義欄位: 這個函式需要一個引數,即文章物件。

設定全域性文章資料。

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
function setup_postdata( $post ) {
global $wp_query;
if ( ! empty( $wp_query ) && $wp_query instanceof WP_Query ) {
return $wp_query->setup_postdata( $post );
}
return false;
}
function setup_postdata( $post ) { global $wp_query; if ( ! empty( $wp_query ) && $wp_query instanceof WP_Query ) { return $wp_query->setup_postdata( $post ); } return false; }
function setup_postdata( $post ) {
	global $wp_query;

	if ( ! empty( $wp_query ) && $wp_query instanceof WP_Query ) {
		return $wp_query->setup_postdata( $post );
	}

	return false;
}

常見問題

FAQs
檢視更多 >