如何从另一个高级自定义字段获取高级自定义字段选择值? [英] How to get Advanced Custom Field choice value from another Advance Custom Field?
问题描述
我使用高级自定义字段插件创建了两个自定义字段。我希望它的行为就像在一个文本字段中插入值时一样,应该在另一个字段中将其填充为选择字段。
I have created two custom fields using Advanced Custom Field plugin. I want it to behave like when I insert value in one text field, it should be filled in the another field which is a choice field.
此图像是我在其中插入Name值和slug值的示例。
我希望它返回此值。
This image is an example where I am inserting Name value and slug value. I want it to return this.
推荐答案
要自动填充ACF中的选择字段,可以使用load_field函数-在此处查看更多信息: http://www.advancedcustomfields.com/resources/acfload_field/
To auto populate select fields in ACF, you can use the load_field function - see more here: http://www.advancedcustomfields.com/resources/acfload_field/
因此,假设您选择的字段名称是 marke_name ,则可以将以下内容添加到您的functions.php文件中,这将每次为您填充该字段
So, let's say your select field name was marke_name, you could add the following to your functions.php file and this will populate the field every time for you
function acf_load_marke_name_field_choices($field)
{
global $post;
//Get the repeater field values
$choices = get_field('repeater_field_name',$post->ID);
// loop through array and add to field 'choices'
if (is_array($choices)) {
foreach ($choices as $choice) {
//Set the select values
$field['choices'][$choice['slug']] = $choice['name'];
}
}
// return the field
return $field;
}
add_filter('acf/load_field/name=marke_name', 'acf_load_marke_name_field_choices');
这篇关于如何从另一个高级自定义字段获取高级自定义字段选择值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!