Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Preview not working with Published Pages #16006

Open
altescape opened this issue Jun 5, 2019 · 61 comments
Open

Preview not working with Published Pages #16006

altescape opened this issue Jun 5, 2019 · 61 comments
Labels
Needs Dev Ready for, and needs developer efforts [Type] Bug An existing feature does not function as intended

Comments

@altescape
Copy link

Describe the bug

I'm using a fresh install of the latest WordPress (v5.2.1) and latest Advanced Custom Fields Pro (v5.8.1), with no other plugins installed.

  • Once a page is published, changing and previewing content does not work.
  • Furthermore it hides the ACF content, but when clicking preview again shows the content - but is an older version of the content, clicking preview again then hides the content and so on.

It should be noted that when a page is not published it works correctly. If I switch the page back to draft the preview works correctly.

To reproduce
Steps to reproduce the behavior:

  1. Install ACF Pro 5.8.1 and create a field group with a text field called title, and show it on all posts that are pages (I can provide export of this code if needed)
  2. Add <?php the_field('title'); ?> after line 17 of template-parts/content/content-page.php of twentynineteen theme
  3. Create a page and write something in ACF Title like 'This is an ACF Title', then preview
  4. Should see 'This is an ACF Title' on page
  5. Then publish page
  6. Change content of ACF Title to 'This is an ACF Title 123' and click preview
  7. You should see no ACF Title
  8. Then click preview again
  9. Should see 'This is an ACF Title' (noting that '123' had not been added)
  10. Click preview again
  11. Should not see ACF Title
  12. You can click preview again and again to toggle hide/show of ACF content

Expected behavior

  • A up-to-date preview of the changed Advanced Custom Fields content.
  • When previewing the page multiple times WordPress should not be toggling showing/hiding of Advanced Custom Fields content

Screenshots

Preview working on unpublished pages:

preview-on-unpublished-works-lg

Preview not working on published pages:

preview-on-published-not-working

Previewing multiple times toggles the content on and off:

preview-on-published-toggles-content

Desktop (please complete the following information):

  • OS: OSX
  • Browser chrome
  • Version [74.0.3729.169 (Official Build) (64-bit)]

Additional context

  • Please add the version of Gutenberg you are using in the description: Whatever is used in WordPress 5.2.1
  • Here is a JSON export so the custom fields can be easily recreated, just save as a file and import using Custom Fields > Tools > Import Field Groups:
[
    {
        "key": "group_5cf7bf8106d4d",
        "title": "Page",
        "fields": [
            {
                "key": "field_5cf7bf875b9ca",
                "label": "Title",
                "name": "title",
                "type": "text",
                "instructions": "",
                "required": 0,
                "conditional_logic": 0,
                "wrapper": {
                    "width": "",
                    "class": "",
                    "id": ""
                },
                "default_value": "",
                "placeholder": "",
                "prepend": "",
                "append": "",
                "maxlength": ""
            }
        ],
        "location": [
            [
                {
                    "param": "post_type",
                    "operator": "==",
                    "value": "page"
                }
            ]
        ],
        "menu_order": 0,
        "position": "acf_after_title",
        "style": "default",
        "label_placement": "top",
        "instruction_placement": "label",
        "hide_on_screen": [
            "permalink",
            "the_content",
            "excerpt",
            "discussion",
            "comments",
            "revisions",
            "slug",
            "author",
            "format",
            "page_attributes",
            "featured_image",
            "categories",
            "tags",
            "send-trackbacks"
        ],
        "active": true,
        "description": ""
    }
]
@talldan
Copy link
Contributor

talldan commented Jun 11, 2019

Thanks for the details @altescape, really great bug report.

Out of interest, if you save the post (cmd+s/ctrl+s) before clicking preview do you see the latest changes? If so, that might be a (not ideal) workaround.

The issue might be that the fix (#14877) for the previous preview issue (#12617) involved disabling the saving of metaboxes when the preview button is clicked. Unfortunately the metabox save process was causing post revisions to be deleted.

I created an issue #14900 to consider ways to re-enable metabox saving when previewing. It's not a simple thing to fix unfortunately.

@altescape
Copy link
Author

altescape commented Jun 12, 2019

Thanks for the heads up @talldan - I'll have a look also at the issue you created.

cmd+s didn't work, WordPress only allows saving when I've edited WordPress blocks and not metaboxes, thank you for the tip though - I'll wait for further updates regarding this.

@corywebb
Copy link

I am seeing a similar issue without ACF. Preview is not working on an already-published post if an autosave of the post exists. Here are the steps to reproduce:

  1. Create a post.
  2. Publish the post.
  3. Close the post editor, and then re-open the post.
  4. Make a change to the post, and then close the editor without saving. You should see an alert that asks if you want to leave the page. Click the "Leave" button to leave the page.
  5. Re-open the post again, and note the "There is an autosave..." message at the top of the editor.
  6. Make a different change to the post, and click the "Preview" button.
  7. Note that the preview does not show the change(s) made in step 6.

The preview works for me when an autosave does not exist, but it does not work when an autosave exists.

@tomjn
Copy link
Contributor

tomjn commented Jun 18, 2019

@altescape is there an equivalent ACF support post? It'd be good to cross reference and debug faster. It's possible this is an ACF specific issue, but if it isn't it'd be good for debugging to track down where things go wrong and improve Gutenberg accordingly

@amanda-t
Copy link

@tomjn Most recent thing I've seen from ACF is AdvancedCustomFields/acf#186

@corywebb
Copy link

corywebb commented Jul 1, 2019

@tomjn this issue isn't just happening with ACF. See my previous comment above: #16006 (comment)

@dartiss
Copy link

dartiss commented Jul 2, 2019

This issue is occurring for a WordPress VIP client. If anyone within the Automattic Gutenberg team are able to look at this, it would be appreciated.

@jweston491
Copy link

This bug is still occurring for me.

Using Twenty-Nineteen with 5.2.2 with ACF Pro 5.8.2

@andreabrunato
Copy link

This bug till occurring for me, only in preview of published posts.
Using Sage Roots theme (customized by me), WP 5.2.2 e ACF Pro 5.8.2.
Both in local server and online.

@newhope
Copy link

newhope commented Aug 1, 2019

Still occurring for me.
Need to switch back to classic editor.

@cyberphen
Copy link

Can confirm, happening with me.

@ejke
Copy link

ejke commented Aug 13, 2019

Adding my voice, occurring to me as well.
Wordpress 5.2.2, ACF Pro 5.8.3.

I solved the problem temporarily by installing and activating Disable Gutenberg plugin, but as I would like to be able to use both ACF and Blocks, it's not a long-term solution.

@atomiccherry
Copy link

Experiencing same issue as well.

@df165
Copy link

df165 commented Sep 27, 2019

Also experiencing this issue. Edit: ejke's solution of installing Disable Gutenberg plugin worked for me.

@jg314
Copy link
Contributor

jg314 commented Nov 3, 2019

A few of us are taking a look at this at WordCamp US Contributor Day. We're able to replicate this issue in a number of scenarios within WordPress 5.2.4.

  • We tested with both an Advanced Custom Fields meta field, but also with a generic meta field added via add_meta_box().
  • We tested with the Gutenberg plugin v6.8.0 both activated and deactivated.

In every case, the preview works correctly when the post is a draft, but once published, the preview doesn't update the meta field content.

@joppuyo
Copy link

joppuyo commented Apr 1, 2020

Hey, I also have this problem. If I enable Classic Editor the preview works properly but when using Gutenberg the preview does not update custom fields if the post has been published.

In my opinion, Gutenberg should also save post meta changes when creating a preview as it worked before.

While "Just make everything a block" is probably the "Gutenberg way" of solving things, it doesn't work in all cases. Let's say you have a custom post type called "Event" and you want to use Gutenberg editor with it. You probably want custom fields called start_time and end_time so you can properly query the posts elsewhere on your site. You also probably want to show these fields in the post template. If you would save this data into blocks, it's impossible to query since it's stored as JSON in the post content.

So this bug prevents using preview properly when using custom fields and Gutenberg together.

@jnicol
Copy link

jnicol commented Apr 9, 2020

This longstanding bug still exists in April 2020: Changes to custom fields are not reflected when previewing a published post. I tested with WP 5.4, 2020 theme and all plugins disabled.

Although this bug report specifically mentions the ACF plugin, it affects all custom fields.

The only "solution" I can find is to install the Classic Editor plugin.

@hubertnguyen
Copy link

hubertnguyen commented Apr 22, 2020

Actually, it's my post content updates that are not showing in the preview. It's really weird and creates a lot of friction in the workflow.

Solution for now: if I save and refresh the current /wp-admin/post.php?post=[POSTID]&action=edit page, the preview works again, until next time. Sigh.

@thomascharbit
Copy link

Is there any update on this issue?
Any workaround?

It's been a while..

@KevinRay
Copy link

KevinRay commented Apr 27, 2020

Seeing this with WP5.4. Installing the Classic Editor plugin worked for us.

@Erutan409
Copy link

I have the Classic Editor plugin installed and this is still occurring for me. Latest WordPress version.

@Khoded-Andy
Copy link

I have managed to fix this by installing and activating the Disable Gutenberg plugin and defining WP_POST_REVISIONS to 3:

define( 'WP_POST_REVISIONS', 3 );

Seems to have done the trick for published posts/pages.

Unbelievable that an issue like this has been known for so long and Gutenberg is even considered a MVP. Crazy. But here we are. Hopefully this fix works for others as well.

@lnikell
Copy link

lnikell commented Apr 1, 2021

sounds crazy that the default WP editor does not work with the most popular ACF plugin that used on almost every website

@Sjardo
Copy link

Sjardo commented Apr 14, 2021

I would love to see an update on this issue!

@ayohdev
Copy link

ayohdev commented Apr 14, 2021

This is becoming a major issue. Clients are wanting both ACF and Gutenberg. Not be able to preview page content before publishing is not easy to sell to a client.

@jmccall75
Copy link

This is becoming a major issue. Clients are wanting both ACF and Gutenberg. Not be able to preview page content before publishing is not easy to sell to a client.

It's an issue with post meta in general, right? Not ACF specific?

@rahulsg91097
Copy link

rahulsg91097 commented Jun 21, 2021

I was facing the same issue and was able to tackle this issue by using this plugin: WP Revisions Control.

@lnikell
Copy link

lnikell commented Jul 2, 2021

@rahulsg91097 it won't help because it does not fix the Gutenberg issue. So I suppose you also disabled the Gutenberg editor.

@EdithAllison
Copy link

Following as I'm having the same problem. We are using ACF to add fields to page templates and Gutenberg editor for the main content part. Preview is broken due to missing ACF fields. Disabling Gutenberg is not an option as we also need to use custom blocks and patterns. I don't have a solution but a fix would greatly improve our usage of WP.

@tolkadot
Copy link

I've just had to install the classic editor to overcome this issue on a new site. So disappointing.
Will this be addressed before support for the classic editor plugin expires on December 31, 2021 ?

@todeveni
Copy link

Will this be addressed before support for the classic editor plugin expires on December 31, 2021 ?

Classic editor support is extended at least through 2022.

@TimDix
Copy link

TimDix commented Nov 26, 2021

I tried to use the Yoast Duplicate Post plugin as a workaround for this issue. There's a Rewrite & Republish feature which lets you save the ACF Meta fields to the draft, and therefore I can get working previews. And I found it worked even better than expected. The Preview works fully without saving drafts and includes ACF Meta updates.

Workaround Steps:

  1. Install Yoast Duplicate Post
  2. Go to plugin settings and enable it for the post type which uses ACF Meta fields and gutenberg editor
  3. Click Rewrite & Republish on a post of your choice
  4. Update your ACF field data
  5. Click Preview, Preview in new Tab
    You should see your ACF Meta fields are now properly updated in the preview!

https://wordpress.org/plugins/duplicate-post/

Not an ideal workaround since it requires extra steps, however it's workable and can be built into workflow to just always Rewrite & Publish for updates.

Perhaps this workaround can help identify a basis for an official solution?

WordPress Version 5.8.2
ACF Pro Version 5.11.1
Yoast Duplicate Post Version 4.2

@okadots
Copy link

okadots commented Dec 17, 2021

Having the same issue where ACF fields that are not blocks don't update in preview once a page is made live.

The solution posted here (the one from darkly77 at the bottom) is working for me.
https://support.advancedcustomfields.com/forums/topic/custom-fields-on-post-preview/

@stefanfisk
Copy link
Contributor

I just now discovered that I am also affected by this when previewing pages that use ACF blocks. Said workaround seems to work.

@lichtmetzger
Copy link

lichtmetzger commented May 19, 2022

The solution posted here (the one from darkly77 at the bottom) is working for me. https://support.advancedcustomfields.com/forums/topic/custom-fields-on-post-preview/

It does work somewhat because it shows the current state of a site before doing any further edits. New changes are not reflected in the preview though, making the preview at least do something, but still not being very useful.

The preview seems to work fully when creating a new page, though, which is nice.

@kory-northrop
Copy link

Another year has gone by without any updates. What is the status of a fix for this issue? It still exists....

@dipak-webo
Copy link

Guys I wonder, when autosaved it creates a new row in the posts table with a unique ID, why can't save meta values referencing to this ID? Isn't it simple? My project actually heavily depends on meta values and when I can't preview them, it's so weird.

@tripflex
Copy link

tripflex commented Mar 25, 2024

Almost 5 years later and now Gutenburg is the default editor, how is this not something being looked at all?? This is not just an issue with ACF, it's an issue with ANY custom meta boxes.

Is WordPress/Gutenburg of the opinion that these things should be handled by plugins (and not handled natively like it is with classic editor)?

@isuke01
Copy link

isuke01 commented Aug 27, 2024

I wonder if this ever gonna be "fixed".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Needs Dev Ready for, and needs developer efforts [Type] Bug An existing feature does not function as intended
Projects
None yet
Development

No branches or pull requests