Advanced Custom Fields是一款自定义文章字段的插件,功能较为强大,字段可以分组来指派,那么我们如何显示某个字段组下的字段呢?

也就是如何get fields from group,我们需要用到一个方法get_field_object。

<?php   //or insert the ID of your fields Group.  $groupID='116';  $custom_field_keys = get_post_custom_keys($groupID);  foreach ( $custom_field_keys as $key => $fieldkey )  {  if (stristr($fieldkey,'field_'))  {  //echo $key . " => " . $fieldkey . "<br />";  //echo $field['label'] . ': ' . $field['value'];  //echo $fieldkey . "<br />";  $field = get_field_object($fieldkey, $groupID);    $acf_field_name = $field['name'];    $attachment = get_field($acf_field_name);  echo "<img src='".$attachment['url']."' title='".$attachment['title']."'/>";      }  }    ?>

以上代码参考自wordpress.stackexchange.com/questions/95126/acf-get-fields-from-group

www.npspro.cn软师兄
软师兄 » WordPress的Advanced Custom Fields自定义文章字段插件如何获取某个组的字段
50T免费网盘资源大集合【持续更中~~~~】:点击查看