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.
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/
因此,假设您选择的字段名称是 marke_name,您可以将以下内容添加到您的functions.php 文件中,这样每次都会为您填充该字段
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');
关于php - 如何从另一个高级自定义字段获取高级自定义字段选择值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35502576/