Home › Forums › General Issues › Get_fields() returns false until I update the post › Reply To: Get_fields() returns false until I update the post
Actually, no.
This function like all others requires that the field key reference exists in the database for the current $post_id. It uses a combination of the post ID and field name to look up the field key reference.
It all ends with the function acf_get_metadata(). In this function you will find
$meta = get_metadata( $type, $id, "{$prefix}{$name}", false );
$prefix in this case in an underscore (_), so it is trying to get the meta value of the meta key (your field name) prefixed with “_”. This is where the field key reference is stored. This meta value will only be set if the post already has a value for the field.
As stated in the update_field() document
Updating via field key
This example shows how to achieve the same result as above using the field’s key instead of its name. The field’s key should be used when saving a new value to a post (when no value exists). This helps ACF create the correct ‘reference’ between the value and the field’s settings.
The reason this is it because field names can be duplicated. All ACF operations actually need the field key to work. Field keys are unique. When you save a new post in the admin every input name is the field key, not the field name. ACF really has no way of knowing what field you are referencing by a field name and the field name has no meaning without the reference, which is why a field key reference is inserted into the DB for every field value that is saved for every post.
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.