WordPress.org

Make WordPress Core

Opened 11 months ago

Last modified 4 months ago

#45337 new defect (bug)

Strange pagination issue

Reported by: sachit.tandukar Owned by:
Milestone: Future Release Priority: normal
Severity: normal Version: 4.4
Component: Rewrite Rules Keywords: needs-patch needs-unit-tests
Focuses: Cc:
PR Number:

Description

Hi,

I am facing strange pagination issue in WordPress. I could replicate it on other major WordPress websites as well apart from the one I am working on.

If you check this website: https://highlandexpeditions.com/blog/, everything works fine. Pagination works fine too.

However, if you visit https://highlandexpeditions.com/blog/2/, you will get the same page as https://highlandexpeditions.com/blog/. But the pagination links are ruined. You will have pagination links like (https://highlandexpeditions.com/blog/2/page/2/, https://highlandexpeditions.com/blog/2/page/3/) which goes to 404 page.

I think WordPress should show 404 for https://highlandexpeditions.com/blog/2/ rather than showing https://highlandexpeditions.com/blog/.

I don't think it has anything to do with themes or plugin. Because another popular website like https://www.wpbeginner.com/blog/ has the same issue. If you visit this URL (https://www.wpbeginner.com/blog/2/), you will find its pagination URL is wrong. I am able to replicate it on other websites as well.

Thanks.

Attachments (1)

45337.diff (588 bytes) - added by jeremyfelt 4 months ago.

Download all attachments as: .zip

Change History (2)

@jeremyfelt
4 months ago

#1 @jeremyfelt
4 months ago

  • Keywords needs-patch needs-unit-tests added
  • Milestone changed from Awaiting Review to Future Release
  • Severity changed from major to normal
  • Version changed from 4.9.8 to 4.4

Hi @sachittandukar, thanks for opening a ticket.

This seems similar to #28081, but likely different enough to have its own ticket. That deals with the paged query variable and this deals with page. This was partially fixed in #11694, which introduced the current page checking in [34492].

There are (at least) two ways in which this presents itself:

First: when a request is made to any is_singular() post/page with /2/ appended to the URL, WordPress checks for an instance of <!--nextpage--> in the content. If it exists, and it matches the page number, $success is set to true and the page is loaded. If the next page marker does not exist, there is no current check that flags the content for 404 if a page number is part of the URL. For that, we could do something like 45337.diff to return a 404 if content is not paged.

Second: (highlighted in the ticket description), when a page is set as the page_for_posts, is_singular() is false and the logic handling <!--nextpage--> is skipped entirely. Earlier in the process, the query object was populated with posts, so as far as handle_404() is concerned, is_home() is true and the page can be loaded as is. The fix for this seems a little more complicated and _could_ be handled earlier in the process.

Note: See TracTickets for help on using tickets.