Hello,
my question:
I insert values for fields via script using update_field() after I created the posted via wp_insert_post.
Afterwards I can not get the values of the fields using get_field(…) obviously because the field-key is wrong. Of course I could map the field_key by manualy reading it out of the admin-panel througn an array or something. But is there maybe a more automic way of doing this?
Help appreciated
Markus
Remark: I can get the field values after I update the post manualy in the editor. But that’s not a good solution.
Hi @markus.freise
Becuase ACF stores it’s field within the wp_postmeta as a serialized array, there is no real way of searching for the field via it’s field_name.
Sorry, but this is unfortunately not possible with ACF at the moment.
I’ve also been looking for a way to get the key from a name. The best solution I’ve come up with is adding a function which does a switch/case on the field name and applies a filter to return the key. However, it does require that you manually code a case/return/break for each field (probably not practical if you’ve got more than a few dozen fields).
Code here: https://gist.github.com/wells5609/5971010
Alright. I’ll do it the copy and paste-way as mentioned in the docs. 🙂