Title: Bug when adding ACF fields programmatically
Last modified: October 14, 2024

---

# Bug when adding ACF fields programmatically

 *  Resolved [oliver1979](https://wordpress.org/support/users/oliver1979/)
 * (@oliver1979)
 * [1 year, 7 months ago](https://wordpress.org/support/topic/bug-when-adding-acf-fields-programmatically/)
 * If I add ACF fields programmatically within my plugin with the following code,
   the ACF-VC INTEGRATOR SETTINGS popup looks like this (there are two Field name
   selects):
 * Field group (i)
   Test group 1 (selected)Test group 2Field nameTest2 (only one 
   item in the list)Field nameTest2 (only one item in the list)
 * If I change the Field group, nothing happens with both “Field name” select fields.“
   Test2” stays the only item in both selects. If I assign the second field group
   to another post type, it stil does not work.
 *     ```wp-block-code
       add_action('acf/init', 'add_my_custom_fields');function add_my_custom fields() {    acf_add_local_field_group(array(        'key' => 'test_grp1',        'title' => __( 'Test group 1', 'test'),        'menu_order' => 0,        'location' => array (            array (                array (                    'param' => 'post_type',                    'operator' => '==',                    'value' => 'page',                ),            ),        ),        'fields' => array(            array(                'key' => 'field_page_test1',                'label' => __( 'Test1', 'test'),                'name' => 'page_test1',                'type' => 'text',            )        )    ));    acf_add_local_field_group(array(        'key' => 'test_grp2',        'title' => __( 'Test group 2', 'test'),        'menu_order' => 1,        'location' => array (            array (                array (                    'param' => 'post_type',                    'operator' => '==',                    'value' => 'page',                ),            ),        ),        'fields' => array(            array(                'key' => 'field_page_test2',                'label' => __( 'Test2', 'test'),                'name' => 'page_test2',                'type' => 'text',            )        )    ));}
       ```
   

Viewing 4 replies - 1 through 4 (of 4 total)

 *  Plugin Author [Frederik Rosendahl-Kaa](https://wordpress.org/support/users/frederik-rosendahl-kaa/)
 * (@frederik-rosendahl-kaa)
 * [1 year, 7 months ago](https://wordpress.org/support/topic/bug-when-adding-acf-fields-programmatically/#post-18071632)
 * Hi [@oliver1979](https://wordpress.org/support/users/oliver1979/),
 * It sounds strange, can’t quite see why it should work differently when adding
   acf fields programmatically.
   I looked into it and will come back when I know 
   something more or have made a fix.
 *  Plugin Author [Frederik Rosendahl-Kaa](https://wordpress.org/support/users/frederik-rosendahl-kaa/)
 * (@frederik-rosendahl-kaa)
 * [1 year, 7 months ago](https://wordpress.org/support/topic/bug-when-adding-acf-fields-programmatically/#post-18082825)
 * Hi [@oliver1979](https://wordpress.org/support/users/oliver1979/),
 * I have now fixed the error and have released a new version 1.8.6
 *  Thread Starter [oliver1979](https://wordpress.org/support/users/oliver1979/)
 * (@oliver1979)
 * [1 year, 7 months ago](https://wordpress.org/support/topic/bug-when-adding-acf-fields-programmatically/#post-18083382)
 * Many thanks for the fast solution! Will check the new update on Monday.
 *  Thread Starter [oliver1979](https://wordpress.org/support/users/oliver1979/)
 * (@oliver1979)
 * [1 year, 7 months ago](https://wordpress.org/support/topic/bug-when-adding-acf-fields-programmatically/#post-18085442)
 * Works like a charm, thanks!!

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘Bug when adding ACF fields programmatically’ is closed to new replies.

 * ![](https://ps.w.org/acf-vc-integrator/assets/icon-128x128.png?rev=1450656)
 * [ACF-VC Integrator](https://wordpress.org/plugins/acf-vc-integrator/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/acf-vc-integrator/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/acf-vc-integrator/)
 * [Active Topics](https://wordpress.org/support/plugin/acf-vc-integrator/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/acf-vc-integrator/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/acf-vc-integrator/reviews/)

 * 4 replies
 * 2 participants
 * Last reply from: [oliver1979](https://wordpress.org/support/users/oliver1979/)
 * Last activity: [1 year, 7 months ago](https://wordpress.org/support/topic/bug-when-adding-acf-fields-programmatically/#post-18085442)
 * Status: resolved