Support

Account

Home Forums Backend Issues (wp-admin) What are these underscore fields in database?

Solved

What are these underscore fields in database?

  • Hello,
    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,
    Esther

  • 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.

  • Hi John,
    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.
    Thanks,
    Esther

  • 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,
    Esther

Viewing 5 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic.

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.