Opened 3 years ago
Last modified 2 weeks ago
#59027 new defect (bug)
Weekly wp_get_archives has invalid link (link for month instead of year)
| Reported by: | filipac | Owned by: | |
|---|---|---|---|
| Priority: | normal | Milestone: | Future Release |
| Component: | Posts, Post Types | Version: | 0.71 |
| Severity: | normal | Keywords: | has-patch 2nd-opinion has-unit-tests |
| Cc: | Focuses: |
Description
If you call wp_get_archives function with type set to weekly, the resulted link contains two parameters: m => year, w => week.
This results in unwanted behaviour, as you get a month like 2023 which is invalid.
The link should contain ?y={year}&w={week}.
Attachments (2)
Change History (17)
This ticket was mentioned in PR #4979 on WordPress/wordpress-develop by @filipac.
3 years ago
#1
This ticket was mentioned in Slack in #core by nekojonez. View the logs.
3 years ago
#6
@
3 years ago
That is a really old bug indeed.
Since this isnt a regression introduced in 6.3, this will be for 6.4.
But well spotted. And yeah, sometimes small issues fly under the radar and especially when code is being enhanced, sometimes we don't check if the actual code we are enhancing contains a bug.
Besides, I think its a small thing thats quick to glance over.
Anyhow, it will be fixed in 6.4 :D
(Is this a record for longest standing bug ever in WP?)
This ticket was mentioned in Slack in #core by nicolefurlan. View the logs.
3 years ago
#8
@
3 years ago
- Keywords needs-unit-tests 2nd-opinion added
This ticket was discussed during today's 6.4 post-beta 1 scrub.
@costdev brought up a potential BC (backward-compatible) break of changing m to y. This is a valid concern when considering how to move this bugfix forward.
As @joemcgill pointed out:
Definitely needs some deep research and added unit tests, if possible to ensure this doesn't break again in the future.
If there is truly a BC concern, this one might benefit from being in the early early alpha phases of a major release.
I'm marking this one with 2nd-opinion to denote it needs
- Thorough historical review.
- Consideration of how to deal with a BC break.
- If this one should be moved into
earlyalpha phase.
This ticket was mentioned in Slack in #core by oglekler. View the logs.
3 years ago
#10
@
3 years ago
- Keywords early added
- Milestone 6.4 → 6.5
This ticket was discussed during bug scrub.
Due to possible side effects that it may have, it should be an early ticket and I am rescheduling it to the next milestone.
Add props: @mukesh27
This ticket was mentioned in Slack in #core by audrasjb. View the logs.
3 years ago
#12
@
3 years ago
- Milestone 6.5 → 6.6
As per today's bug scrub, we decided to move this ticket to milestone 6.6 to give it more time to be tested.
This ticket was mentioned in Slack in #core by nhrrob. View the logs.
2 years ago
#14
@
2 years ago
- Keywords early removed
- Milestone 6.6 → Future Release
Since this has been punted a bit for a few majors, moving his to Future Release. Also removing early as I'm not quite sure it's needed.
Once the proper deep-dive on this is complete and a path forward is laid out, it can be moved into a specific milestone by an owner.
This ticket was mentioned in PR #15374 on WordPress/wordpress-develop by @sawf1y.
2 weeks ago
#15
- Keywords has-unit-tests added; needs-unit-tests removed
Changed link for weekly wp_get_archives() function. Former link was ?m=2023&w=1. This links leads to working page with correct posts selection. Suggested link ?y=2023&w=1 will lead to page with posts with week w=1 but from all years. Suggested by Claude ?year=2023&w=1 - will work as expected
Claude bug report
?m=2023&w=1 already works. WP_Query reads a 4-digit m as “year only” and adds YEAR(post_date)=2023 with no month condition. So today’s weekly links list the right posts.
The PR’s ?y=2023&w=1 makes things worse. y isn’t a public query var, so WordPress ignores it. The link then shows week 1 of every year. The new link test fails with the PR: the 2022 week link also returned both 2023 posts.
Real bug 1: weeks are dropped across years. The loop skips a result when $result->week === $arc_w_last and ignores the year. So “week 1 of 2022” followed by “week 1 of 2023” (with order => ASC) produces only one link. The fix is to compare year and week together.
Real bug 2: the current week is never marked as current. $selected checks get_query_var( 'year' ), but the link sets m, so year is always 0 and aria-current="page" never appears on weekly archives.
Changing the weekly link from m to year fixes bug 2 and still filters correctly.
Trac ticket: 59027
Use of AI Tools
AI assistance: Yes
Tool(s): Claude Code
Model(s): Opus 5.5
Used for: Researching a bug, researching existing fix, writing fix and tests. All code was reviewed and tested by me
If you call wp_get_archives function with type set to weekly, the resulted link contains two parameters: m => year, w => week.
This results in unwanted behaviour, as you get a month like 2023 which is invalid.
The link should contain ?y={year}&w={week}.
Trac ticket: https://core.trac.wordpress.org/ticket/59027