当我这样做的时候get_post_meta($post->ID, "company_wp_box_g", false)
我正在获取一个键/值对数组。
array (size=1)
0 =>
array (size=7)
\'f_name\' => string \'John Doe\' (length=14)
\'f_company_name\' => string \'Something Ltd\' (length=0)
\'f_description\' => string \'\' (length=0)
\'f_phone\' => string \'0208 992 7222\' (length=13)
\'f_cell_phone\' => string \'07809775200\' (length=0)
\'f_email\' => string \'[email protected]\' (length=0)
\'f_web\' => string \'doe.com\' (length=0)
How to get a single value for example f_name
? 仅供参考一切都在里面发生foreach loop
:
$args = array(
\'numberposts\' => -1,
\'post_type\' => \'company\'
);
$posts = get_posts($args);
foreach ($posts as $post){
// do stuff
}
SO网友:Mridul Aggarwal
如果每个元值都有键f_name
$meta = get_post_meta($post->ID, "company_wp_box_g", true);
echo $meta[\'fname\'];
如果您不确定内容(&P);要搜索第一个可用的
$name = false;
$meta = get_post_meta($post->ID, "company_wp_box_g", false);
foreach($meta as $array) {
if(isset($array[\'f_name\'])) {
$name = $array[\'f_name\'];
break;
}
}
echo $name;