Opened 3 weeks ago
Last modified 3 weeks ago
#65267 new defect (bug)
Preserve Query Strings on Old-Slug Redirects, If Any
| Reported by: |
|
Owned by: | |
|---|---|---|---|
| Milestone: | Future Release | Priority: | normal |
| Severity: | normal | Version: | 2.1 |
| Component: | Query | Keywords: | has-patch has-unit-tests |
| Focuses: | Cc: |
Description
WordPress's wp_old_slug_redirect() (wp-includes/query.php) builds its redirect destination via get_permalink() and drops the original request's query string entirely. This is unexpected, and the option to have query parameters be preserved to the new destination should be available.
A valid usage case is with advertising campaigns that link to old urls containing URL parameters for tracking. Advertisements may exist in permanent form (on paper) with a relevant code in the query string of the URL. If someone modifies the URL in WordPress and wp_old_slug_redirect() handles the redirect and points to the updated slug, then those query parameters should be passed along.
Attachments (1)
Change History (4)
#1
@
3 weeks ago
- Keywords needs-patch added
- Milestone changed from Awaiting Review to Future Release
- Version set to 2.1
This makes sense to me.
I modified the slug of the Hello World post from hello-world to hola-mundo. Then I renamed it back.
When I tried going to /2025/12/25/hola-mundo/?utm=foo I was redirected to /2025/12/25/hello-world/ with the query parameter removed.
The wp_old_slug_redirect() function was introduced in WP 2.1. I'm surprised this hasn't been raised as an issue before.
#2
@
3 weeks ago
At my company, since implementing my bandaid mu-plugin fix, we are seeing a huge ads attribution bump with our traffic that was tied to businesses that closed during covid and reopened nearby recently.
This ticket was mentioned in PR #11916 on WordPress/wordpress-develop by @deepakprajapati.
3 weeks ago
#3
- Keywords has-patch has-unit-tests added; needs-patch removed
## Summary
Preserves the original query string when wp_old_slug_redirect() redirects an old slug to the current permalink.
This keeps tracking params and raw query args intact during the redirect.
## Testing
Run:
`bash
npm run test:php -- --filter Tests_Rewrite_OldSlugRedirect
A workaround (in mu-plugin).