Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure Query Pagination Block Uses Correct Permalink in REST API #69437

Open
wants to merge 1 commit into
base: trunk
Choose a base branch
from

Conversation

geekofshire
Copy link

What?

When retrieving page content via the REST API, the Next/Previous pagination links in the Query Pagination block incorrectly use the REST API endpoint (/wp-json/wp/v2/pages/...) instead of the actual page permalink. This results in broken pagination links that don’t align with the site’s permalink structure. I have noticed this issue in Next and Previous Page links.

Expected Link - http://localhost:8888/test/?query-3-page=2
Actual Link - http://localhost:8888/wp-json/wp/v2/pages/13?query-3-page=2

Closes #69433

Why?

The frontend correctly generates pagination links using the page’s permalink.However, when fetching page content via the REST API, pagination links incorrectly use the API request URL instead of the post’s actual permalink. This may break headless WordPress setups and external API consumers who rely on REST responses.

How?

Modified render_block_core_query_pagination_next() to use get_permalink() instead of relying on $_SERVER['REQUEST_URI'].

Testing Instructions

  1. Create a Page and add a Query Loop block with Pagination (Next/Previous Page).
  2. Save the page and view it on the frontend – pagination links should be correct.
  3. Make a REST API request to fetch the page content:
  4. /wp-json/wp/v2/pages/{id}
  5. Check the Next and Previous page links in the API response – it should be something like http://localhost:8888/test/?query-3-page=2 instead of http://localhost:8888/wp-json/wp/v2/pages/13?query-3-page=2

Testing Instructions for Keyboard

Not required

Screenshots or screencast

Before After

Copy link

github-actions bot commented Mar 5, 2025

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: geekofshire <[email protected]>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@github-actions github-actions bot added the First-time Contributor Pull request opened by a first-time contributor to Gutenberg repository label Mar 5, 2025
Copy link

github-actions bot commented Mar 5, 2025

👋 Thanks for your first Pull Request and for helping build the future of Gutenberg and WordPress, @geekofshire! In case you missed it, we'd love to have you join us in our Slack community.

If you want to learn more about WordPress development in general, check out the Core Handbook full of helpful information.

@t-hamano t-hamano added [Type] Bug An existing feature does not function as intended [Block] Query Pagination Affects the Query Pagination Block - used for pagination within the Query Loop Block labels Mar 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Block] Query Pagination Affects the Query Pagination Block - used for pagination within the Query Loop Block First-time Contributor Pull request opened by a first-time contributor to Gutenberg repository [Type] Bug An existing feature does not function as intended
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Query Pagination Block Generates Incorrect Links in REST API Responses for Next & Prev Pages
2 participants