WordPress:Function Reference/get post custom
來自站長百科
描述[ ]
返回一個(gè)多維數(shù)組,帶有某篇文章的或者網(wǎng)頁的所有自定義fields。也看看get_post_custom_keys() 和get_post_custom_values()
用法[ ]
%%% <?php get_post_custom($post_id); ?> %%%
例子[ ]
默認(rèn)用法[ ]
使用下面的例子,設(shè)置一個(gè)變數(shù)($custom_fields)作為多維數(shù)組,包含當(dāng)前文章所有的自定義field。 <?php $custom_fields = get_post_custom(); ?>
檢索數(shù)組中的數(shù)據(jù)[ ]
下面的例子會(huì)檢索ID是72的文章,關(guān)鍵字為my_custom_field的所有自定義field參數(shù)值(既然這個(gè)關(guān)鍵詞擁有三個(gè)自定義field,參數(shù)值分別是"狗""47"和 "這是另一個(gè)參數(shù)值")。
<?php $custom_fields = get_post_custom(); $my_custom_field = $custom_fields['my_custom_field']; foreach ( $my_custom_field as $key => $value ) echo $key . " => " . $value . "<br />"; ?>
0 => dogs
1 => 47
2 => This is another value
參數(shù)[ ]
相關(guān)的[ ]
add_post_meta(), delete_post_meta(), get_post_meta(), update_post_meta(), get_post_custom_values(), get_post_custom_keys()