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 of custom post type doesn't show subtitle #36

Open
hatsumatsu opened this issue Aug 27, 2018 · 4 comments
Open

Preview of custom post type doesn't show subtitle #36

hatsumatsu opened this issue Aug 27, 2018 · 4 comments

Comments

@hatsumatsu
Copy link
Contributor

hatsumatsu commented Aug 27, 2018

When previewing a custom post type post (via the preview link on the edit post screen) the subtitle doesn't appear.

Looking at the code of includes/subtitle.php (Link) you're checking for a preview_id GET parameter.
It seems that this parameter is not present in custom post types where the URL looks like https://example.com?post_type={custom_post_type}&p={post_id}&preview=true .

I can prepare a PR if required.

@benhuson
Copy link
Owner

If you are able to prepare a PR that would be very welcome.

Thank you

@hatsumatsu
Copy link
Contributor Author

I'm currently running some tests and in my case both wp_get_post_autosave() and wp_get_post_revisions() return false on a custom post type preview.

Everything runs smoothly when I remove the whole if ( is_preview() ) { ... } block in get_raw_subtitle(). Do you remember the reason for this block?

@benhuson
Copy link
Owner

It was originally added by a contributor in this commit to support revisions:
523c9ca#diff-d2289bcd07fd410250cf5d7b237d9d25

It was then reworking in this commit:
b097220

I think it may relate to browsing revisions of a page rather that previewing the page (?)
To test, change the subtitle a few times, then click into a revision of the page and browser the different revisions.

@hatsumatsu
Copy link
Contributor Author

I was able to narrow down the bug: If a draft post has revisions the subtitle is missing in the preview. If there are no revisions (no changes saved in draft mode) the subtitle displays correctly in the preview.

So in the current logic if a post has a revision the latest revision is pulled correctly but it has no subtitle meta data. Could be that it's not saved correctly. I also guess that the problem occurs in custom post types that do not support revisions at all.

In general the nested logic in the function is a little bit confusing since the preview of a post is not nessacarrily related to post revisions.

As another observation I could not get if ( isset( $_GET['preview_id'] ) ) { in Line 84 to return true.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants