get_post_custom_values

函式
get_post_custom_values ( $key = '', $post_id = 0 )
引數
  • (string) $key Optional. Meta field key. Default empty.
    Required:
    Default: (empty)
  • (int) $post_id Optional. Post ID. Default is the ID of the global `$post`.
    Required:
返回值
  • (array|null) Meta field values.
定義位置
相關方法
get_post_custom_keysget_post_customget_post_statusesget_post_statusget_post_states
引入
1.2.0
棄用
-

get_post_custom_values函式用於檢索給定文章的自定義欄位的所有值的陣列。它有兩個引數:第一個引數是自定義欄位的鍵,第二個引數是文章的ID。

檢索自定義文章欄位的值。

引數不能被認為是可選的。所有的文章元欄位都會被檢索到,並且只返回元欄位的關鍵值。

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
function get_post_custom_values( $key = '', $post_id = 0 ) {
if ( ! $key ) {
return null;
}
$custom = get_post_custom( $post_id );
return isset( $custom[ $key ] ) ? $custom[ $key ] : null;
}
function get_post_custom_values( $key = '', $post_id = 0 ) { if ( ! $key ) { return null; } $custom = get_post_custom( $post_id ); return isset( $custom[ $key ] ) ? $custom[ $key ] : null; }
function get_post_custom_values( $key = '', $post_id = 0 ) {
	if ( ! $key ) {
		return null;
	}

	$custom = get_post_custom( $post_id );

	return isset( $custom[ $key ] ) ? $custom[ $key ] : null;
}

常見問題

FAQs
檢視更多 >