Make WordPress Core

Opened 4 years ago

Last modified 2 months ago

#49969 new defect (bug)

Previewing the page designated as "latest posts" shows the frontpage

Reported by: zieladam's profile zieladam Owned by:
Milestone: Future Release Priority: normal
Severity: normal Version:
Component: Posts, Post Types Keywords: needs-patch
Focuses: Cc:

Description (last modified by zieladam)

This continues the discussion from https://github.com/WordPress/gutenberg/issues/2409

The issue

  • Create two pages (let's call them "My home" and "My posts")
  • Go to customizer and set Homepage to be "My home" and Posts page to "My posts"
  • Edit "My posts" in editor mode
  • Press preview
  • Confirm you got "My home" instead of "My posts"

The root cause

When you click "Open preview in new tab" while editing "My posts", Gutenberg redirects to a preview URL like this one:

https://mywpsite.com/?page_id=5&preview_id=5&preview_nonce=12bd60d6f4&preview=true

When you visit that URL, WordPress will load the front page instead of the posts page. This is because class-wp-query.php assumes that posts page is also the front page:

https://github.com/WordPress/WordPress/blob/b4373fafe9b87f75bf9d65e808be8049510dff8b/wp-includes/class-wp-query.php#L1032

Then, when rendering a preview, it substitutes the page_id that was requested with the value of get_option( 'page_on_front' ):

https://github.com/WordPress/WordPress/blob/b4373fafe9b87f75bf9d65e808be8049510dff8b/wp-includes/class-wp-query.php#L1904

If I remove the preview parameters and leave only ?page_id=5, it displays the correct page.

Change History (11)

#1 @zieladam
4 years ago

  • Description modified (diff)

#2 @joyously
4 years ago

As stated in the GitHub issue, that issue was only a continuation of #34005

Last edited 4 years ago by SergeyBiryukov (previous) (diff)

#3 @zieladam
4 years ago

In my understanding, #34005 is about re-enabling the Visual Editor and Page Template dropdown when editing the page for Posts. The discussion in the Gutenberg issue https://github.com/WordPress/gutenberg/issues/2409 pivoted towards the results of previewing the page marked as "Posts page" - which indeed is unexpected due to a bug. I believe this constitutes it's own issue.

Last edited 4 years ago by SergeyBiryukov (previous) (diff)

This ticket was mentioned in Slack in #core by joyously. View the logs.


4 years ago

This ticket was mentioned in Slack in #core by joyously. View the logs.


4 years ago

#6 @SergeyBiryukov
4 years ago

  • Keywords needs-patch added
  • Milestone changed from Awaiting Review to Future Release

This ticket was mentioned in Slack in #core by joyously. View the logs.


3 years ago

#8 @poena
5 months ago

#59438 was marked as a duplicate.

#9 @poena
5 months ago

I am testing with Twenty Twenty-Four on WordPress version 6.4.2 and it is working for me, I believe it has been fixed:
When I am in the post editor, editing the page that I have assigned as the blog page, and I click on "View page", it shows me the correct template and content.

#10 @bvoynick
4 months ago

This is still a problem in 6.4.3.

As noted in the description, reproduction requires choosing both a home page and a separate posts/blog page. If only a posts/blog page is set, this preview bug does not occur.

#11 @poena
2 months ago

I figured out what I did wrong in my testing, and I can confirm that this is still an issue in 6.5x:

In the block editor, I had clicked on "View Page", and this only uses the page slug, not the
page id, preview id, or nonce.

Clicking on the button that says "View" instead of "View Page", and then selecting
"Preview in new tab" in the drop down, does show the page selected as the homepage instead of the blog page.

Note: See TracTickets for help on using tickets.