#45337 closed defect (bug) (fixed)
Strange pagination issue
Reported by: | sachit.tandukar | Owned by: | SergeyBiryukov |
---|---|---|---|
Milestone: | 5.5 | Priority: | normal |
Severity: | normal | Version: | 4.4 |
Component: | Rewrite Rules | Keywords: | needs-patch needs-unit-tests |
Focuses: | Cc: |
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)
Change History (11)
#1
follow-up:
↓ 5
@
5 years 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
#5
in reply to:
↑ 1
@
4 years ago
Replying to jeremyfelt:
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 totrue
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 ashandle_404()
is concerned,is_home()
istrue
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.
Thanks for the detailed comment!
[47727] should fix the first item, let's keep the ticket open for the second item.
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 withpage
. This was partially fixed in #11694, which introduced the currentpage
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 totrue
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 ashandle_404()
is concerned,is_home()
istrue
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.