Home › Forums › General Issues › get_field returning null after update › Reply To: get_field returning null after update
Here is a possible fix for those using get_field() for non ACF fields. This is untested. Most of it is pulled out of the function acf_get_metadata().
add_filter('acf/load_value', 'get_meta_or_option_for_acf_get_field', 20, 3);
function get_post_meta_for_acf_get_field($value, $post_id, $field) {
if ($value !== NULL) {
return $value;
}
$decoded = acf_decode_post_id( $post_id );
$id = $decoded['id'];
$type = $decoded['type'];
if (!$id) {
return $value;
}
$name = $field['name'];
if ($type === 'option') {
return get_option("{$id}_{$name}", NULL);
} else {
$meta = get_metadata($type, $id, $name, false);
return isset($meta[0]) ? $meta[0] : NULL;
}
}
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 Cookie Policy. If you continue to use this site, you consent to our use of cookies.