Home › Forums › Bug Reports › Bug: acf_get_reference() is returning incorrect field reference › Reply To: Bug: acf_get_reference() is returning incorrect field reference
If you are using wp_insert_post() then
1) There cannot be a post ID before it is inserted, you will only have the correct post ID after it is inserted.
2) The fields will not exist on the newly inserted post. Even with the correct post ID the fields will not exist and ACF will fail to find the reference and fail to update the field. When adding/updating fields that do not exist you must use the field keys, see the update_field() documentation.
Field keys, unlike field names, must be unique to your entire WP site. All field keys must be unique, they cannot be repeated in multiple field groups. If you have duplicate field keys then this is more then likely the source of your issue.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!