Skip to content

Instantly share code, notes, and snippets.

@ChrisLTD
Created May 8, 2014 16:22
Show Gist options
  • Save ChrisLTD/892eccf385752dadaf5f to your computer and use it in GitHub Desktop.
Save ChrisLTD/892eccf385752dadaf5f to your computer and use it in GitHub Desktop.
Fix so you can preview ACF field changes in Wordpress admin
<?php
/*
Debug preview with custom fields
Taken from: http://support.advancedcustomfields.com/forums/topic/preview-solution/
See also: http://support.advancedcustomfields.com/forums/topic/2nd-every-other-post-preview-throws-notice/
*/
add_filter('_wp_post_revision_fields', 'add_field_debug_preview');
function add_field_debug_preview($fields){
$fields["debug_preview"] = "debug_preview";
return $fields;
}
add_action( 'edit_form_after_title', 'add_input_debug_preview' );
function add_input_debug_preview() {
echo '<input type="hidden" name="debug_preview" value="debug_preview">';
}
@SiteBoltsAdmin
Copy link

We noticed today that WordPress's "Preview Changes" feature wasn't working correctly for ACF fields; the preview was showing their published values rather than the previewed values.

We tried out several suggested PHP snippets but found that they didn't resolve the issue.

After seeing this suggestion:

define( 'WP_POST_REVISIONS', 3 );

We did some testing and confirmed that the issue occurs when post revisions are disabled. In our case, it was due to our WordPress host (WPEngine) disabling post revisions by default. We were able to fix it by contacting their support and having them set the number of post revisions to 3.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment