Support

Account

Home Forums Bug Reports Bug: acf_get_reference() is returning incorrect field reference Reply To: Bug: acf_get_reference() is returning incorrect field reference

  • @hube2 thanks for your response.

    Yes, I am passing the correct post ID in the update_row() function. It’s all happening in the backend using a webhook. I built a plugin to dynamically create posts and update ACF fields.

    So the problem occurred, when I duplicated the field group for “post type A” and renamed it for “post type B”. I ensured that the location is unique. Now, every time when the plugin dynamically creates a post in “post type A”, basically uses the repeater field from the “post type B”. This does not happen when I manually create a post from WP admin.

    I believe that because the field group for “post type B” was created later, update_row() is somehow picking the _products field key from “post type B” instead of the correct “post type A”.

    Here’s the code if it can help:

    
    $images = isset( $data['images'] ) ? $data['images'] : array();
    $post_id = isset( $data['post_id'] ) ? $data['post_id'] : '';
    $swingline_id = isset( $data['swingline_id'] ) ? $data['swingline_id'] : '';
    $acf_key = isset( $data['acf_key'] ) ? $data['acf_key'] : '';
    $acf_repeater_key_values = isset( $data['acf_repeater_key_values'] ) ? $data['acf_repeater_key_values'] : '';
    $row_index = isset( $data['row_index'] ) ? $data['row_index'] : 1;
    
    $new_images = $this->helpers->upload_images( $images, $post_id, $swingline_id );
    
    if ( ! empty( $new_images ) && is_array( $new_images ) ) {
    	$acf_repeater_key_values['_images'] = $new_images;
    }
    
    $updated = update_row( $acf_key, $row_index, $acf_repeater_key_values, $post_id );
    

    I hope this helps to understand the problem. I really think it’s a bug which ACF devs should look into. I can help with more details if needed.