Make WordPress Core

Opened 3 months ago

Last modified 2 months 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
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 (2)

#1 follow-up: @poena
2 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
2 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

Note: See TracTickets for help on using tickets.