Home › Forums › General Issues › Get_fields() returns false until I update the post › Reply To: Get_fields() returns false until I update the post
@hube2 This is what i was going to do…but are you saying don’t use acf_maybe_get_field()? With my broken data, it seems to work well. I can get the field_key by passing it the name of the field and the post id. I was going to do something simple like this.
function helper_get_field_key($field_name, $post_id){
$maybe_field_obj = acf_maybe_get_field( $field_name, $post_id, false );
return $maybe_field_obj['key'];
}
$get_field_key_email = helper_get_field_key('email', $post_id);
print_r($get_field_key_email);
Returns: field_5f401336ed966
This output the field key for the email field that is in that post id.
If there is a better way to get the field_key programmatically when no value exists yet, I’m all ears…Would love to have a function to use just to get the field key.
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.