Support

Account

Home Forums General Issues Saved Drafts not displaying custom fields Reply To: Saved Drafts not displaying custom fields

  • Aloha Elliot,

    I have traced the issue (on vanilla WordPress) to a change in version 5.9.2 to includes/acf-meta-functions.php. The result is that ACF postmeta does not get created for revision IDs in the database. This happens whether you are saving a draft, or updating a published page. This means:
    * if you try to preview an unpublished revision, you won’t see any ACF fields (the original problem in this thread);
    * if you try to browse revisions, you will see empty ACF postmeta for all the revisions
    * if you try to restore a revision, it won’t have any ACF postmeta associated with it, causing the post’s ACF fields to be deleted.

    Because of that 3rd point, this is probably higher severity. Here’s the diff that causes the issue in acf_update_metadata():

    @@ -240,17 +238,14 @@ function acf_update_metadata( $post_id = 0, $name = '', $value = '', $hidden = f
        return false;
      }
    
    - // Update option.
    - if( $type === 'option' ) {
    -
    + // Determine CRUD function.
    + if( function_exists("update_{$type}_meta") ) {
    +   return call_user_func("update_{$type}_meta", $id, "{$prefix}{$name}", $value);
    + } else {
        // Unslash value to match update_metadata() functionality.
        $value = wp_unslash( $value );
        $autoload = (bool) acf_get_setting('autoload');
        return update_option( "{$prefix}{$id}_{$name}", $value, $autoload );
    -
    - // Update meta.
    - } else {
    -   return update_metadata( $type, $id, "{$prefix}{$name}", $value );
      }
     }
    
    

    I can confirm that reverting the change above restores functionality (i.e., ACF saves postmeta to revision IDs when saving/updating a post).

    These are related changes (to acf_get_metadata() and acf_delete_metadata()), just in case they are relevant:

    
    diff --git a/includes/acf-meta-functions.php b/includes/acf-meta-functions.php
    index 1d26f03..9e8c81a 100644
    --- a/includes/acf-meta-functions.php
    +++ b/includes/acf-meta-functions.php
    @@ -196,14 +196,12 @@ function acf_get_metadata( $post_id = 0, $name = '', $hidden = false ) {
        return null;
      }
    
    - // Check option.
    - if( $type === 'option' ) {
    -   return get_option( "{$prefix}{$id}_{$name}", null );
    -
    - // Check meta.
    - } else {
    -   $meta = get_metadata( $type, $id, "{$prefix}{$name}", false );
    + // Determine CRUD function.
    + if( function_exists("get_{$type}_meta") ) {
    +   $meta = call_user_func("get_{$type}_meta", $id, "{$prefix}{$name}", false);
        return isset($meta[0]) ? $meta[0] : null;
    + } else {
    +   return get_option( "{$prefix}{$id}_{$name}", null );
      }
     }
    
    @@ -286,14 +281,12 @@ function acf_delete_metadata( $post_id = 0, $name = '', $hidden = false ) {
        return false;
      }
    
    - // Update option.
    - if( $type === 'option' ) {
    + // Determine CRUD function.
    + if( function_exists("delete_{$type}_meta") ) {
    +   return call_user_func("delete_{$type}_meta", $id, "{$prefix}{$name}");
    + } else {
        $autoload = (bool) acf_get_setting('autoload');
        return delete_option( "{$prefix}{$id}_{$name}" );
    -
    - // Update meta.
    - } else {
    -   return delete_metadata( $type, $id, "{$prefix}{$name}" );
      }
     }