Wordpress Metabox:如何获取具有多个值的字段的值?
我正在使用此 WordPress Metabox 框架:http://www.deluxeblogtips。 com/p/meta-box-script-for-wordpress.html
这是代码,
array(
'name' => '<strong>Robots Meta</strong>',
'desc' => '',
'id' => $prefix . 'robot',
'type' => 'radio',
'options' => array(
'if' => 'index, follow',
'in' => 'index, nofollow',
'nf' => 'noindex, follow',
'nn' => 'noindex, nofollow'
),
),
我如何调用模板中每个单选值的值?
我尝试这样做,但它只检查它是否已设置:
$metas = get_post_meta(get_the_ID(), 'hiro_robot', false);
foreach ($metas as $meta) {
echo $meta;
}
if (in_array($val, $metas)) {
echo "$val is set";
} else {
echo "$val is not set";
}
im using this Wordpress Metabox framework: http://www.deluxeblogtips.com/p/meta-box-script-for-wordpress.html
here is the code
array(
'name' => '<strong>Robots Meta</strong>',
'desc' => '',
'id' => $prefix . 'robot',
'type' => 'radio',
'options' => array(
'if' => 'index, follow',
'in' => 'index, nofollow',
'nf' => 'noindex, follow',
'nn' => 'noindex, nofollow'
),
),
how do i call the value of each of the radio values in the template?
i tried doing this but it only checks if it is set or not:
$metas = get_post_meta(get_the_ID(), 'hiro_robot', false);
foreach ($metas as $meta) {
echo $meta;
}
if (in_array($val, $metas)) {
echo "$val is set";
} else {
echo "$val is not set";
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我喜欢使用简短的辅助函数来获取元值。
任何时候使用此功能时,您想要回显元键的值,您可以使用:
如果您想返回值:
此外,在您的答案中,您不需要使用
get_the_ID()
函数使用$post->ID
I like to use a short helper function for grabbing meta values.
When using this anytime you want to echo the value of a meta key you can use:
If you want to return the value:
Also in your answer you don't need to use the
get_the_ID()
function just use$post->ID
在这里我自己弄清楚了,事情是这样的:
here i figured it out myself, here it goes like this: