问题描述: 当我编辑或新增一个字段后,发现在编辑 Advanced Custom Fields(ACF)字段组后,新增的字段没有显示出来。
解决方法:
确保你已经保存了编辑的字段组。ACF字段组需要保存才能更新字段列表。
检查你的代码中是否正确调用了字段组。确保你在正确的位置调用了get_field()
或the_field()
函数来获取字段的值。例如:
// 获取字段组中某个字段的值
$value = get_field('field_name');
// 输出字段组中某个字段的值
the_field('field_name');
// 在页面模板中显示字段组
if (is_page_template('template-name.php')) {
the_field('field_name');
}
// 在特定文章类型中显示字段组
if (get_post_type() === 'custom_post_type') {
the_field('field_name');
}
acf_add_local_field_group()
函数注册字段组,并使用acf_add_local_field()
函数注册字段。例如:// 注册字段组
acf_add_local_field_group(array(
'key' => 'group_key',
'title' => 'Group Title',
'fields' => array(
// 注册字段
array(
'key' => 'field_key',
'label' => 'Field Label',
'name' => 'field_name',
'type' => 'text',
),
),
'location' => array(
// 设置字段组显示位置
array(
array(
'param' => 'post_type',
'operator' => '==',
'value' => 'post',
),
),
),
));
通过以上方法,你应该能够解决“编辑/新增的字段在编辑ACF字段组后没有显示出来”的问题。记得检查你的代码是否正确,并且保存字段组的修改。
上一篇:编辑/更新一个Pod的YAML