Opened 2 years ago
Closed 8 months ago
#52324 closed defect (bug) (duplicate)
Sample permalinks unavailable for attachment pages.
Reported by: |
|
Owned by: | |
---|---|---|---|
Milestone: | Priority: | normal | |
Severity: | normal | Version: | |
Component: | Media | Keywords: | close |
Focuses: | Cc: |
Description
Both get_page_link()
and get_post_permalink()
accept a third parameter $sample
to generate permalinks for unpublished posts (draft
, future
, etc).
get_attachment_link()
does not include this third parameter and will always generate an ugly formatted link for attachment pages.
For example instead of w.org/future-post/future-attachment
the attachment page is always shown as w.org/?attachment_id=4
.
To reproduce:
- Create a post leave it in draft
- Upload some new media
- Link it to the attachment page
- Observe that it uses the ugly URL format.
Change History (4)
#2
@
2 years ago
- Keywords close added
Thanks for looking in to this.
For posts published immediately it looks like _fix_attachment_links()
resolves this. As I was testing scheduled posts at the time it looks like I hit #36976 so it's possible this ticket can be closed as a near enough duplicate of that.
While investigating #52373, I was considering changin the default permalink to /attachment/{$attachment->post_name}
but that would require rewriting _fix_attachment_links()
so it might be a terrible idea.
Adding the close keyword for the media folks to decide whether to treat this as a duplicate.
Hey,
I can reproduce the issue.
I tried some stuff, and the issue does not seem to come from
get_attachment_link
function. After some debugging, I realised it's because the parent link (post link) is not a pretty permalink yet, so it will behttp://localhost:8889/?post_type=post&p=393
for example.Then in
get_attachment_link
, it does not accept a parent link like this, so it will fallback and return something like:w.org/?attachment_id=4
.So the issue is rather on:
get_permalink
call does not return a pretty URL for a draft post parent.