Home › Forums › General Issues › Get_fields() returns false until I update the post › Reply To: Get_fields() returns false until I update the post
@hube2 What function should I use to get the field key for this scenario? I can pass the field name and the post id to whatever function to get the field key. I am building a new custom importer, so i need a way to get the field key before any value has been stored into the field. I thought acf_maybe_get_field would be the ticket. It seems to work great.
I have some data that suffers from not having the reference data in the database. However when i edit the post, i see all of the fields filled in on the edit post screen. I know the data is there, but the data was imported via field name not field key.
I want to rectify this error in my new importer.
This data was imported using a custom script. I did some experimentation. I had tried function get_fields(), get_field_object(), get_field_objects() – none of these worked to get field data. They all returned empty.
I do not want to hard code the field keys into my importer because the field keys will change from environment to environment. I work in a 4 environment. local, test, staging, and prod. Just looking for a way to get the field keys programmatically. That’s why i was going to use acf_maybe_get_field to get the field key and then save the data using wp_insert_post and run a script that also update_fields using the field keys during the import process.
What function should i use to get the field keys?
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!