Home › Forums › Bug Reports › issues related to field key references › Reply To: issues related to field key references
Hi,
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
if( !$field)
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!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.