Opened 18 years ago
Closed 16 years ago
#4396 closed defect (bug) (fixed)
Permalink leads to wrong attachment
Reported by: |
|
Owned by: | |
---|---|---|---|
Milestone: | 2.8 | Priority: | normal |
Severity: | normal | Version: | 2.2 |
Component: | Upload | Keywords: | has-patch commit |
Focuses: | Cc: |
Description
Problem:
Some permalinks lead to wrong attachments.
My WordPress 2.2 configuration:
- Date and time based permalinks
- Uploads organized into month and year based folders
Way to reproduce the problem:
- Write a new post, attach a new file with title of 'one', then publish the post
- Write a second post, attach a new file with title of 'one', then publish the post
- Write a third post, attach a new file with title of 'one', then publish the post
Resulting permalinks for the attachment:
- First post: http://test/2007/06/03/first-post/one/
- Second post: http://test/2007/06/03/second-post/one-2/
- Third post: http://test/2007/06/03/third-post/one-2/
Going to those links shows the correct file for the first and the third post. However the link for the second post shows the file of the third post.
All files are uploaded correctly, the problem is only in the link.
Attachments (1)
Change History (8)
#6
@
16 years ago
- Component changed from General to Upload
- Keywords commit added; wrong attachment permalink removed
- Milestone changed from 2.9 to 2.8
- Owner anonymous deleted
works for me under current trunk (2.8), all uploads get unique slugs, but it seems to only be because the post_title is passed to wp_insert_attachment() uniquely, upload "one.jpg" and the 2nd time the title will be "one1"
The original patch seems to be still be relevant, particularly for plugins which add attachments.
Note: See
TracTickets for help on using
tickets.
Am I correct in my assumption, that the attachment slugs should be unique in WordPress?
If it is true, I can see an obvious flaw in wp_insert_attachment() function in /wp-includes/post.php:
Currently the unique name check looks like this:
So the name check uses different SQL queries for the first check and for all subsequent ones. If indeed the attachment slugs should be globally unique, then the second query shouldn't have the post_parent check.
Like this:
I tried the modification above, and the attachment slugs are unique now.