I’m using WordPress with ACF to manage the postmeta. When I look on my database, I found for each postmeta records created by ACF, an input like this :
meta_key : _example
meta_value : field_5ea808b820138
What is this for ?
What will happen if I delete this input ?
If I want to insert manually an input “example” in this postmeta table, should I create also a “_example” input ? If yes, what should I put in the meta_value ?
This is the ACF field key reference. In your example ‘_example’ tells ACF which field key is used for ‘example’. Without it ACF will not know what type of field it is or allow ACF to format the return value correctly.
Yes, if you want to insert data manually the field key reference must be inserted. The best way to do this is to use the field key when updating a field that does not already have data in the database
update_field('field_5ea808b820138', $value, $post_id);
For more information see the documentation here https://www.advancedcustomfields.com/resources/update_field/
field_5ea808b820138 is the field key. This is a unique id given to your field by ACF. Fields are stored as posts, that are a custom post type named acf-field. The information about the field is stored in the post table like any other post type. The settings of the field are in the post and meta values related to the post.
That depends on the field type. You will see problems on the front of the site. For basic fields that store text in the database there will not be a problem. But for a field like a post object field for example, this stores a post ID. ACF will not know what to do with the ID value and will return an integer instead of a post object. Any field that does not store a text value will not work on the front end.
Probably, unless it is a sub field.
Generally, it’s not a good idea to insert values into the DB without using ACF update_field() using the field key as I mentioned above, or not inserting the field key reference if you’re using some other way to insert the data. Because of the various ways that fields can be added there isn’t any way to predict what might not work. The only way that you can be sure that things will work is if you edit and update every post in the admin after the data is added which likely defeats the purpose of adding it any other way. All import plugins that are ACF aware manage this.
You must be logged in to reply to this topic.
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!
© 2022 Advanced Custom Fields.