get_post_meta

函式
get_post_meta ( $post_id, $key = '', $single = false )
引數
  • (int) $post_id Post ID.
    Required:
  • (string) $key Optional. The meta key to retrieve. By default, returns data for all keys. Default empty.
    Required:
    Default: (empty)
  • (bool) $single Optional. Whether to return a single value. This parameter has no effect if `$key` is not specified. Default false.
    Required:
    Default: false
返回值
  • (mixed) An array of values if `$single` is false. The value of the meta field if `$single` is true. False for an invalid `$post_id` (non-numeric, zero, or negative value). An empty string if a valid but non-existing post ID is passed.
定義位置
相關方法
get_site_metaget_post_timeget_post_timestampdelete_post_metaget_post_meta_by_id
引入
1.5.0
棄用
-

get_post_meta函式檢索特定post-meta欄位的值。它有三個引數:第一個引數是文章的ID,第二個引數是元欄位的名稱,第三個引數是一個布林值,指示檢索到的值應該是單個值還是一個值陣列。

為給定的文章ID檢索一個文章元欄位。

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
function get_post_meta( $post_id, $key = '', $single = false ) {
return get_metadata( 'post', $post_id, $key, $single );
}
function get_post_meta( $post_id, $key = '', $single = false ) { return get_metadata( 'post', $post_id, $key, $single ); }
function get_post_meta( $post_id, $key = '', $single = false ) {
	return get_metadata( 'post', $post_id, $key, $single );
}

常見問題

FAQs
檢視更多 >