Make WordPress Core

Opened 10 months ago

Last modified 12 days ago

#61157 new defect (bug)

Blocks Query pagination NEXT & PREV produce incorrect URLs when queried via REST API

Reported by: yelbaev's profile yelbaev Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version: 5.8
Component: Permalinks Keywords: needs-patch close
Focuses: rest-api Cc:

Description

Core/query block when rendered by REST API call, for example /wp-json/v2/pages/%ID%, generates incorrect URLs for Prev and Next buttons.

URLs get generated based on $_SERVER['REQUEST_URI'] instead of current page permalink.

Example: for prev link I get /wp-json/wp/v2/pages/80?query-19-page=1 instead of /portfolio/?query-19-page=1

As far as I can see, it's caused by the use of add_query_arg function without url to work on. Adding get_permalink() as a last parameter fixes the issue

https://github.com/WordPress/WordPress/blob/97c3f240341043e8a0063a7ddfa40797c4a1ee19/wp-includes/blocks/query-pagination-previous.php#L48

https://github.com/WordPress/WordPress/blob/97c3f240341043e8a0063a7ddfa40797c4a1ee19/wp-includes/blocks/query-pagination-next.php#L58

Change History (5)

#1 follow-up: @poena
10 months ago

  • Keywords reporter-feedback added

Hi @yelbaev
Can you include more detailed information about how to test for this problem?

Also I want to confirm if by adding version 5.8 to the ticket, did you mean that the problem was introduced in 5.8, or are you actually testing on 5.8 and no later WordPress versions?

Since this is a problem with a block, did you already search if this has been reported in the Gutenberg repository?
I was not able to find a perfect match, but sometimes this is because of how the issues are worded.
Open issues for the query pagination block: https://github.com/WordPress/gutenberg/issues?q=is%3Aopen+is%3Aissue+label%3A%22%5BBlock%5D+Query+Pagination%22

#2 in reply to: ↑ 1 @yelbaev
10 months ago

  • Keywords reporter-feedback removed

Replying to poena:

Can you include more detailed information about how to test for this problem?

Steps to replicate on :
1) Create new page and place a query block in it
2) Request the page via REST API /wp-json/wp/v2/pages/$ID and in content -> rendered you'll get a paged URL for NEXT and/or PREV that is incorrectly based on API endpoint rather than on page url

See it https://yelbaev.com/portfolio/ vs https://yelbaev.com/wp-json/wp/v2/pages/80
https://tinyurl.com/23acd7ay

Or here's a short video https://youtu.be/Uf2Ul730gqM

Also I want to confirm if by adding version 5.8 to the ticket, did you mean that the problem was introduced in 5.8, or are you actually testing on 5.8 and no later WordPress versions?

I tracked back from current version to older and found out that this bug was in initial block implementation

Since this is a problem with a block, did you already search if this has been reported in the Gutenberg repository?

Checked, no open tickets on this matter

#3 @geekofshire
3 months ago

I was able to reproduce this issue in the 6.7.1 Version, IMO this should be fixed in pagination block as we already have filters to modify the generated pagination link.

Last edited 12 days ago by geekofshire (previous) (diff)

#4 @poena
2 months ago

  • Keywords close added

Issues related to blocks are managed in the Gutenberg GitHub repository, and a new issue needs to be opened there. After that, this ticket needs to be closed.

The files listed can not be changed through patching WordPress core, since they would be overwritten when the block related changes are copied from Gutenberg to core.

#5 @geekofshire
12 days ago

I have created a issue on Gutenberg Repo - https://github.com/WordPress/gutenberg/issues/69433

Note: See TracTickets for help on using tickets.