I noticed some weird behavior in WP.

I've created custom fields through ACF Plugin. I've also coded a function that can update posts and custom fields at the same time with wp_post_update and update_post_meta functions.

When I update a post from the backend editor, some new lines are added in the postmeta table. Some kind of revisions I guess. But it does not occur when using my own functions. The modification is OK but no new lines in the DB.

Is this a normal behavior ?


Here is my custom code :

    $post_update = array(
      'ID'           => $postid,
      'post_title'   => $title,
      'post_content' => $description,

    $update_post = wp_update_post($post_update);
    update_post_meta( $postid, 'nom_adherent', $name); 

No problem with that code. But If I try to update the post manually from backend editor, WP adds data in the meta_key like _nom_adherent and in the meta_key like field_5b759e3860abd columns.

I don't understand

  • Could you please share more details, such as your code and the particular postmeta that is being added? Without that it's not really possible to assist.
    – WebElaine
    Aug 23 '18 at 15:52
  • I just edited my post
    – Pierre
    Aug 23 '18 at 16:15

Advanced Custom Fields doesn't just save the meta value, it also adds meta with information about the custom field used to save that meta. That's what you're seeing.

Meta with the key _nom_adherent and value field_5b759e3860abd tells ACF when using get_field( 'nom_adherent' ) what custom field was used to create that value, so that it can apply things like the "Return format" setting of the field to the raw value, which is stored as the nom_adherent (no _) meta value.

These will only be created when saving through the front end or updating the meta with the proper ACF functions, like update_field(), not just update_post_meta().

  • OK I got it. The problem is that new lines are added on every post update, even if the custom field value is unchanged. This is stupid. Then it becomes a bit tricky to get correct values from the meta table when data are duplicated. I wanted to use custom fields to store unique values for each post, and they are not unique at all in the end ... I'll have to make it another way. Thanks though.
    – Pierre
    Aug 23 '18 at 17:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.