Home › Forums › Bug Reports › issues related to field key references › Reply To: issues related to field key references
I have a similar issue: I have to import some data from a MySQL DB, and with an older version of ACF I just used field names (so I could cycle easily on the querys’ result rows) to store values with update_field, and get_field retrieved them perfectly.
I recently updated to the last version of ACF, and get_field stopped working unless I edited the post and saved, which I can’t do given the size of my data (thousands of posts).
Trying to solve the issue, I found that in function get_field_object() in core/api.php there is a test
It happens that when get_field is retrieving a field with a temporary field key (e.g. field_myfieldname) $field at that point is an array with all the correct keys, but no values.
Changing the line to
if( !$field || !$field['key'])
to detect an empty key enables the execution of the following code
// treat as text field $field = array( 'type' => 'text', 'name' => $orig_field_key, 'key' => 'field_' . $orig_field_key, ); $field = apply_filters('acf/load_field', $field, $field['key'] );
which seems to fix the problem and retrieve the data.
I can imagine there would be problems with some types of field, but it’s OK for me since they are text fields.
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!
ACF wouldn’t be so widely used in WordPress if it didn’t have some pretty amazing capabilities. In this article, we look at a few of the features we’ll discuss during “7 things you didn’t know you could do with ACF” at #WPEDecode later this month. https://t.co/5lnsTxp81j pic.twitter.com/Yf0ThPG1QG— Advanced Custom Fields (@wp_acf) March 16, 2023
© 2023 Advanced Custom Fields.