[wp-trac] [WordPress Trac] #63041: wp_get_canonical_url always returns false for attachments
WordPress Trac
noreply at wordpress.org
Sun Mar 30 23:32:53 UTC 2025
#63041: wp_get_canonical_url always returns false for attachments
-------------------------------------------------+-------------------------
Reporter: othernoel | Owner: audrasjb
Type: defect (bug) | Status: closed
Priority: normal | Milestone: 6.9
Component: Canonical | Version: 6.4.3
Severity: normal | Resolution: fixed
Keywords: has-patch has-unit-tests has- | Focuses:
testing-info |
-------------------------------------------------+-------------------------
Changes (by audrasjb):
* status: reviewing => closed
* resolution: => fixed
Comment:
In [changeset:"60108" 60108]:
{{{
#!CommitTicketReference repository="" revision="60108"
Canonical: Use `get_post_status()` to determine whether the post has a
`publish` post status in `wp_get_canonical_url()`.
This changeset fixes an issue where `wp_get_canonical_url()` always
returned `false` for attachments. Attachments have a `inherit` post status
rather than `publish`. The `wp_get_canonical_url()` function was directly
checking `$post->post_status === 'publish'`, causing it to always return
`false` for attachments. Using `get_post_status()` fixes the issue as if
the post is an attachment, then the parent post status will be given
instead.
Follow-up to [37685].
Props othernoel, ankitkumarshah, SirLouen,
Fixes #63041.
}}}
--
Ticket URL: <https://core.trac.wordpress.org/ticket/63041#comment:6>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list