php - 如何从另一个高级自定义字段获取高级自定义字段选择值?

标签 php wordpress advanced-custom-fields

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.

Custom Field 1

This image is an example where I am inserting Name value and slug value. I want it to return this.

enter image description here

最佳答案

要自动填充 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/

相关文章:

javascript - 我想在 javascript 语法中包含 php 语法

javascript - 为我的所有图片添加一个与src无关的data-src,以改善WordPress环境中的延迟加载功能

php - 在 Woocommerce 交易电子邮件中显示产品 ACF 字段值

php - ACF : repeater fields returning erratic API data and new fields won't accept new data on save

html - :after 中的 Wordpress 背景图片

php - iPhone SDK 付款后,我的 php IPN 回调中缺少 POST 参数

php - FuelPhp 关系查询作为单一结果

PHP从子窗口向父窗口传递数据

php - div 之间不需要的空间的问题

html - 无法弄清楚 CSS 来更改 Toggle_Sidebar 背景颜色