Home Forums Backend Issues (wp-admin) update_field on new post creates mismatched meta_keys before save_post() Reply To: update_field on new post creates mismatched meta_keys before save_post()

  • We’ve been doing a bit of troubleshooting. The problem seems to lie with a failed field GUID lookup, having provided a top-level field name.

    • Clicking the “Publish” or “Update” button executes actions that do not get executed by manually calling the save_post action. This means that the database contains errant meta keys and values for myfield, _myfield, field_myfield and field_###########
    • wp_insert_post() does execute the save_post action, but again does not produce the final meta key/value associations required
    • During this in-between state of wp_insert_post() and manually updating the post, get_field_object() returns empty field definitions since the $field_key variable contains the name of a field that does not have a corresponding meta value
    • Executing acf/save_post manually does not work as the function requires a populated $_POST variable. Manually saving the post works, since the $_POST object contains field GUIDs, then calls acf/update_value
    • acf/update_value fails because $field is an empty field definition
    • Updating fields with their GUIDs works fine at any point

    It seems that we need a solid way to update fields that are attached to a programmatically-created post before the post ACF meta data has been initialized.