Attachment Page Showing Multiple Files, All With Same Name
-
I’ve done a bunch of searching on this and I can’t figure out if this is a problem with my code or whether this is just how WordPress works.
I have many attachment pages on my site that are showing multiple images (instead of just the one). All of the images being shown have the same filename, but only one is the correct image – and belongs to the post.
Take this post for example:
http://www.playerwives.com/nhl/detroit-red-wings/tomas-holmstroms-wife-annelie-holmstrom/
If you click on the third attachment, you’ll see this page:
That page is showing two images – but only the second one is the one it *should* be showing.
I’d prefer to somehow fix the query that is returning multiple images in the first place, but I would settle for a way to do a check within the loop to determine whether the current photo belongs to the current post. I’m not sure how to determine what the current post is, from the attachment page.
-
Can you replicate the problem using the default Twenty Fifteen theme with all plugins deactivated?
It looks like the problem exists for me because of how old my blog is. I would guess that WordPress, at some point, allowed attachments to be uploaded with identical “post_name” values.
So I just spun up a new droplet with base WordPress install, no plugins, etc. I created two posts, then uploaded a file with the same filename to each (but different files). WordPress didn’t allow them to have the same post_name, and did not exhibit the problem. However, when I changed the post_name of both attachments to be the same thing – the problem occurred.
So the problem is matching post_name values, something WordPress no longer allows – but apparently did at some point.
Anyone know of any consequences to manually changing the “post_name” value for the offending images? I was going to do this manually in the database itself – would that cause any problems? Is the “post_name” field for attachments used for anything beyond a situation like this?
The topic ‘Attachment Page Showing Multiple Files, All With Same Name’ is closed to new replies.