Arrays Wordpress通过元框ID获取自定义字段
我正在write posts面板中注册多个元数据库。在functions.php中:Arrays Wordpress通过元框ID获取自定义字段,arrays,wordpress,function,Arrays,Wordpress,Function,我正在write posts面板中注册多个元数据库。在functions.php中: $meta_boxes[] = array( 'id' => 'products', 'title' => 'Products', 'pages' => array('post', 'page', 'link'), // multiple post types, accept custom post types 'context' => 'normal',
$meta_boxes[] = array(
'id' => 'products',
'title' => 'Products',
'pages' => array('post', 'page', 'link'), // multiple post types, accept custom post types
'context' => 'normal', // normal, advanced, side (optional)
'priority' => 'high', // high, low (optional)
'fields' => array(
array(
'name' => 'something',
'id' => $prefix . 'something',
'desc' => 'some description',
'type' => 'checkbox'
),
//continue with other fields
)
);
//another metabox
$meta_boxes[] = array(
'id' => 'customers',
'title' => 'Customers',
//etc...
我可以使用以下方法获取帖子中所有字段的值:
$custom_field_keys = get_post_custom_keys();
foreach ( $custom_field_keys as $key => $value ) {
$valuet = trim($value);
if ( '_' == $valuet{0} )
continue;
echo $value . ":<br />";
echo get_post_meta($post->ID, $value, true) . "<br/><br/>";
}
$custom_field_keys=get_post_custom_keys();
foreach($key=>$value的自定义字段\键){
$valuet=修剪($value);
如果(''=$valuet{0})
继续;
echo$value.“:
”;
echo get_post_meta($post->ID,$value,true)。“
”;
}
如何获取指定的元框中所有字段的名称和值。例如,获取metabox id“products”中字段的所有值。我的建议是查看这在db中是如何表示的(可能在Posteta表中),并使用$-wordpress db connection类使用post id和字段名称的元框名称查询db-实际上已经有人这样做了,作为meta box的扩展-在meta box网站上看到了一个参考。谢谢!我在db表中查看了一下,发现没有任何列具有metabox名称。也许我必须添加我自己的列来实现这一点。wordpress插件开发中的一种已知做法是将这样的数据存储在选项表或其他地方的数组中,可能不是一个单独的列。但请放心,它在数据库的某个地方。。否则它就不存在了。。我确信插件中没有硬编码。因此,查询/搜索整个wordpress数据库,您将找到答案