Home Forums General Issues Preview solution !


Preview solution !

  • Hi !
    After an half day of research, we found a solution for preview with ACF (and all custom fields in WP).

    The problem :
    If you change an ACF value (or any wp custom fields) but not the title, the content or other native fields, the post (or page) doesn’t change for WP…
    And when you press the preview button, if there is an autosave, WP delete it because the autosave and the saved post (or page) are the same (title, content,… haven’t change).

    I don’t know why WP do that like that but we have the solution (put this code on your function.php file):

       Debug preview with custom fields 
    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">';

    The first hook add a field to check for revisions (debug_preview).
    And the second add an hidden field (debug_preview) on edit pages with a value (‘debug_preview’ but any value works).

    When WP check for revision, the field ‘debug_preview’ doesn’t exist in database but exist with a value in the edit page, so it’s different and WP make the autosave.

    Say “hello back” to preview in WP 🙂

    I hope this code can help you !

    Elliot, if you can add this fix in ACF, it will be great 🙂

    Have a nice day !

  • Hi @Ivan D.

    This solution is fantastic! Great work. I’ll be sure to add it into the next release!


  • This is awesome thanks!

  • Hi @Ivan D.

    I just tested the code, but I can’t reproduce the solution.

    After ore testing, I can’t reproduce the issue at all…

    Without the code, I can simple click on the preview button and view changes to the ACF values. Revisions, however, are not created.

    Perhaps you can shine some light on the issue / solution


  • Hi @elliot,
    It works without our solution and you can’t reproduce the problem ?
    Or you have the problem but our solution doesn’t solve it ?

  • @elliot
    Because the probleme appears only if you don’t modify any native fields like content, title…

    If you create a new post/page/post-type (a draf) the probleme doesn’t appear (because the title is different than the saved title I think).

    But if you edit a post/page/post-type without changing the title or the content or other native wp fields, the first time you click on the preview button all works fine.
    But the second time you hit the preview button, the modification disappear and the save post/page/post-type is shown. And the next time preview works again and next time save post is shown… (yes it’s strange ><‘)

    So on edit post/page/post-type without native wp fields modifications (title, content…) , once on two the preview doesn’t works and the “preview” show the saved post/page/post-type.

    By the way our solution works with all post meta (not only ACF), like Yoast SEO plugin.

    I’m french, so sorry if my english is a little broken :/

  • @elliot
    A little image to explain the problem without our solution 😉

  • Hi @Ivan D.

    Your wireframes are brilliant! Thanks mate. Very clear. I’ll do some more testing with editing an existing post!


  • Hi guys.

    I’ve just solved the issue of WP 3.6 revisions and I think it may also solve this preview bug too!

    The revision bug I am referring to is here:

    The latest code on github includes the new fix. Can you test it out and let me know if it solves this issue too?


  • @elliot
    I’ve download the latest code on github and delete our code : the problem is back :/
    But with your latest and our code it works pretty well 😉

  • Hi @Ivan D.

    Bugger! I’ll read over this thread again and do some more testing.

    Is there any chance that this issue is specific to your WP setup? eg: theme / plugins?

    Can you re-produce the issue on a blank install?

    Thanks for all your time on this one

  • Hi @elliot.

    I’ve made a little video on a blank install 😉

  • Hi @Ivan D.

    Thanks for the video. It is very clear what is going wrong!
    Now the fun part… trying to fix it!


  • Hi @elliot
    It’s a WordPress bug, not an ACF bug 😉 (same problem with all post meta)
    I can make a video with for exemple Yoast SEO -> same problem.
    Our code fix that bug.

    Have a nice day.

  • Holy. Heck.

    This is great—I’ve been bashing my head against the wall trying to figure out what was going on with this whole postmeta black-hole issue. I have encountered it with both ACF and another custom plugin which leverages postmeta to store supplementary content.

    I’m off to test this immediately.

    Is the WP community at large aware that this behaviour is occurring? I’ve done a bunch of poking around, but can’t find any formal documentation of this bug anywhere, but I can concur that it definitely exists.

  • I believe I am experiencing this issue as well. Changes made to a post don’t reflect in preview unless ‘save’ is hit by user. Any tips on a helpful way to diagnose the issue?

  • EDIT: Nevermind. All is still working!

  • The preview works for the main administrator role but not other roles (e.g. Editor and Contributor).

    My solution was to go to /wp-admin/users.php?page=roles&action=edit&role=editor and click Fields and then grant manage_options.

    I then logged in as an Editor and hid the now exposed custom fields but editing a page, clicking on “Screen Options” and unchecking “Custom Fields”.

    This is not ideal because it opens up options that other roles really shouldn’t see.

  • I have the solution above implemented on my site but it no longer works.


  • We’re seeing some issues with preview not working on WordPress 4.6.1 and ACF 5.4.5. It shows the default WP fields, but zero custom fields. The only way around it is to publish the post and then they appear. Any thoughts?

  • I’m also finding that this solution no longer works suddenly – help!

  • EDIT: Just realised this is a necro’d thread.

    Seeing a very similar problem to the one above.

    ACF content on preview mode when a new article is created doesn’t appear until the user triggers a state change (from draft to published or pending review).

    Seems to be a relative new issue.

  • While we wait for a code update (I filed a ticket) with our fingers crossed, I have noticed that if I change a Draft’s visibility to Private from Public, each time I preview, the fields will display.

    So not great. But temporarily workable.

  • sadly we have the same issue with 4.6.1 and lates ACF Pro
    the workaround with public/private works for now – thanks for that!
    still I hope this issue will be fixed soon 🙁

    the funny part seems to be, that my colleague mentioned it may work when he repeatedly clicks on preview. every 4th or so time it seems to work..?

Viewing 25 posts - 1 through 25 (of 65 total)

The topic ‘Preview solution !’ is closed to new replies.