Skip to content

Permalinks: Preserve query arguments in old slug redirects#12633

Open
ArkaPrabhaChowdhury wants to merge 2 commits into
WordPress:trunkfrom
ArkaPrabhaChowdhury:trac-40032-preserve-query-arguments
Open

Permalinks: Preserve query arguments in old slug redirects#12633
ArkaPrabhaChowdhury wants to merge 2 commits into
WordPress:trunkfrom
ArkaPrabhaChowdhury:trac-40032-preserve-query-arguments

Conversation

@ArkaPrabhaChowdhury

Copy link
Copy Markdown

Trac ticket: https://core.trac.wordpress.org/ticket/40032 | Preserves request query arguments when wp_old_slug_redirect() redirects an old post slug, with focused PHPUnit regression coverage.

Copilot AI review requested due to automatic review settings July 22, 2026 07:10
@github-actions

Copy link
Copy Markdown

Test using WordPress Playground

The changes in this pull request can previewed and tested using a WordPress Playground instance.

WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser.

Some things to be aware of

  • All changes will be lost when closing a tab with a Playground instance.
  • All changes will be lost when refreshing the page.
  • A fresh instance is created each time the link below is clicked.
  • Every time this pull request is updated, a new ZIP file containing all changes is created. If changes are not reflected in the Playground instance,
    it's possible that the most recent build failed, or has not completed. Check the list of workflow runs to be sure.

For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation.

Test this pull request with WordPress Playground.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates wp_old_slug_redirect() so that when WordPress redirects from an old post slug to the current permalink, it preserves the original request’s query string (e.g., tracking parameters), and adds a PHPUnit regression test to validate the behavior.

Changes:

  • Append request query arguments to the redirect destination URL in wp_old_slug_redirect().
  • Add a PHPUnit regression test covering query-argument preservation for old-slug redirects.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
src/wp-includes/query.php Preserves request query arguments by appending $_GET to the computed redirect URL.
tests/phpunit/tests/rewrite/oldSlugRedirect.php Adds regression coverage ensuring query arguments survive an old-slug redirect.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/wp-includes/query.php Outdated
Comment on lines +1127 to +1129
if ( ! empty( $_GET ) ) {
$link = add_query_arg( wp_unslash( $_GET ), $link );
}
Comment on lines +61 to +67
public function test_old_slug_redirect_preserves_query_arguments() {
$query_args = array(
'utm_source' => 'test1',
'utm_medium' => 'test2',
'utm_campaign' => 'test3',
);
$old_permalink = add_query_arg( $query_args, user_trailingslashit( get_permalink( self::$post_id ) ) );
Copilot AI review requested due to automatic review settings July 22, 2026 08:11

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.

@ArkaPrabhaChowdhury
ArkaPrabhaChowdhury marked this pull request as ready for review July 22, 2026 08:37
@github-actions

Copy link
Copy Markdown

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.

Core Committers: Use this line as a base for the props when committing in SVN:

Props arkaprabhachowdhury.

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants