由于ACF使用“ACF”类型的自定义帖子作为组,因此我们可以使用get\\u page\\u by\\u title检索组的ID,然后执行其余操作。下面是一个小的实用函数:
// This was tested with ACF free edition v4.4.11
function get_group_fields($group_name){
$group = get_page_by_title($group_name, OBJECT, \'acf\');
if(empty($group)) return false;
$meta = get_post_meta($group->ID);
$acf_fields = array();
foreach($meta as $key => $value){
$acf_meta_key = stristr($key,\'field_\'); // acf fields all start with "field_"
if($acf_meta_key) $acf_fields[] = get_field_object($key);
}
return $acf_fields; // returns an array of field objects
}
用法:
$group_fields = get_group_fields(\'My marvelous group\');
foreach($group_fields as $field){
$label = $field[\'label\'];
$value = $field[\'value\'];
// etc...
}