I started using ACF and want to migrate my old database (not posts) to posts and metapost in WordPress. Now I see that when I publish in the wp-admin a custom post with custom fields, each field gets two rows: fieldname with the value of the field and _fieldname with a long fieldnumber.
I tried to find the use for this underscore-field, but could not find it.
It is probably there for a reason.
So my questions are:
– can anyone refer me to documenation about this?
– any tips how to code the creation of these fields with the correct value. Or should I open and save each post in the wp-admin 🙁 ?
Thanks in advance,
I don’t think there is documentation specifically on this. These are the field key reference to each field. This is how ACF knows what field the value belongs to so it knows how to handle that value. There is a paragraph explain it on this page https://www.advancedcustomfields.com/resources/update_field/
How you create this value depends on how you are migrating the database. All meta values should be copied with importing.
A bigger problem that you’re going to have is any field that is storing an ID value, for example, image, gallery, post object and relationship field all store post IDs of the related object. Most imports create new IDs for posts and this means that all of the existing values will be wrong.
thanks for the fast respons. The link is certainly informative.
I understand from that text that ACF is using the field’s key reference for formatting the data. In my case it is text (that should not give problem) and relations between two custom post-types (that might become a problem, because it probably needs special field settings).
I am migrating from tables outside the wp-databases, so all posts that I create will be new.
It is just php, reading a table, going through all records, for each record create a post with wp_insert() and for each custom field create a metapost referring to this post with add_post_meta(). I did not find creation-functions in the ACF API, so I use the WP functions.
I already migrated two tables with only text fields and there are no field keys. A soon as I open the post in wp-admin and save, then the field keys are there.
I conclude from the information and some trials, that the field’s key reference is not specific for each record, but for the custom field. So I only have to save a post with custom fields in wp-admin once, and the reference is set.
If that conclusion is incorrect I would appreciate to hear that, but I consider the issue solved now.
No, the field key reference is added for every field for every post.
Rather than using add_post_meta() you can use the function update_field() using the field key for that field and ACF will manage it for you.
OK, I’ll do that, thanks,
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!
A few people have asked so I put together a guide on creating @wp_acf blocks together with the ACF Theme Code Pro plugin.— Phil Kurth (@mishtershmart) November 29, 2019
I hope this helps clarify the shortcuts on offer when building custom blocks for the #WordPress block editor.https://t.co/7UqPEc5NRH
© 2019 Advanced Custom Fields. Subscribe