【发布时间】:2018-11-18 02:28:50
【问题描述】:
我正在使用 wordpress 多站点。我有一个要求,我想向现有的 ACF 中继器组添加一个字段。以下是我尝试过的。
add_action('acf/init','add_field');
function add_field(){
acf_add_local_field(array(
'key' => 'field_asdfaas1234ww',
'label' => 'price_xyz',
'name' => 'price_xyz',
'type' => 'text',
'instructions' => '',
'parent' => 'field_568a6ed7971d2',
'required' => 0,
'conditional_logic' => 0,
'wrapper' => array (
'width' => '',
'class' => '',
'id' => '',
),
'default_value' => '',
'placeholder' => '',
'prepend' => '',
'append' => '',
'formatting' => 'html',
'maxlength' => '',));
}
以下是现有 ACF 组的导出代码,仅供参考..
if( function_exists('acf_add_local_field_group') ):
acf_add_local_field_group(array (
'key' => 'group_59ce208402798',
'title' => 'price_group',
'fields' => array (
array (
'key' => 'field_568a6ed7971d2',
'label' => 'pricing',
'name' => 'pricing',
'type' => 'repeater',
'instructions' => '',
'required' => 0,
'conditional_logic' => 0,
'wrapper' => array (
'width' => '',
'class' => '',
'id' => '',
),
'row_min' => '',
'row_limit' => '',
'layout' => 'table',
'button_label' => 'Add Row',
'min' => 0,
'max' => 0,
'collapsed' => '',
'sub_fields' => array (
array (
'key' => 'field_568a6f4f971d3',
'label' => 'group_name',
'name' => 'group_name',
'type' => 'taxonomy',
'instructions' => '',
'required' => 0,
'conditional_logic' => 0,
'wrapper' => array (
'width' => '',
'class' => '',
'id' => '',
),
'taxonomy' => 'product_cat',
'field_type' => 'select',
'allow_null' => 0,
'load_save_terms' => 0,
'return_format' => 'id',
'multiple' => 0,
'add_term' => 1,
'load_terms' => 0,
'save_terms' => 0,
),
array (
'key' => 'field_568a6f65971d4',
'label' => 'width',
'name' => 'width',
'type' => 'text',
'instructions' => '',
'required' => 0,
'conditional_logic' => 0,
'wrapper' => array (
'width' => '',
'class' => '',
'id' => '',
),
'default_value' => '',
'placeholder' => '',
'prepend' => '',
'append' => '',
'formatting' => 'html',
'maxlength' => '',
),
array (
'key' => 'field_568a72a5ffda9',
'label' => 'no_of_doors',
'name' => 'no_of_doors',
'type' => 'text',
'instructions' => '',
'required' => 0,
'conditional_logic' => 0,
'wrapper' => array (
'width' => '',
'class' => '',
'id' => '',
),
'default_value' => '',
'placeholder' => '',
'prepend' => '',
'append' => '',
'formatting' => 'html',
'maxlength' => '',
),
array (
'key' => 'field_568a72baffdaa',
'label' => 'price_norway',
'name' => 'price_norway',
'type' => 'text',
'instructions' => '',
'required' => 0,
'conditional_logic' => 0,
'wrapper' => array (
'width' => '',
'class' => '',
'id' => '',
),
'default_value' => '',
'placeholder' => '',
'prepend' => '',
'append' => '',
'formatting' => 'html',
'maxlength' => '',
),
array (
'key' => 'field_568b5cae9ff93',
'label' => 'price_swedish',
'name' => 'price_swedish',
'type' => 'text',
'instructions' => '',
'required' => 0,
'conditional_logic' => 0,
'wrapper' => array (
'width' => '',
'class' => '',
'id' => '',
),
'default_value' => '',
'placeholder' => '',
'prepend' => '',
'append' => '',
'formatting' => 'html',
'maxlength' => '',
),
),
),
),
'location' => array (
array (
array (
'param' => 'post_type',
'operator' => '==',
'value' => 'product',
),
),
),
'menu_order' => 0,
'position' => 'normal',
'style' => 'seamless',
'label_placement' => 'top',
'instruction_placement' => 'label',
'hide_on_screen' => '',
'active' => 1,
'description' => '',
));
endif;
但由于某种原因,我无法通过我的代码 function add_field 添加字段。各位大神能帮忙吗
【问题讨论】:
标签: php wordpress advanced-custom-fields