I have thousands of imported posts with many ACFs (import via WP All Import).
I had issues with the acf/format_value/name=xyz filter and had a look at the DB.
I found out that the posts which cause the issues have no underscore _fields in the database, only fields (just the meta values).
A manual way to fix the issue would be to edit each post and update it. By saving all the _fields get created.
What is the best way to do this automatically? Which hook triggers the _field creation?
When you used WP All Import did you use the ACF extension? If you did then this should not happen and I’d contact them about it. If you did not use this extension then that’s what caused it. It is practically impossible to import ACF fields without an ACF aware plugin.
There isn’t a hook that triggers the ACF field key reference to be created. When you update a post ACF uses the field keys in the input fields for the name value. ACF uses the field key to look up the correct field name and update the value. It can’t be done in the reverse order and impossible to generate all of the correct field key references based on the values.