[wp-trac] [WordPress Trac] #16830: url_to_postid() doesn't resolve attachments when rewrite rules are disabled
WordPress Trac
noreply at wordpress.org
Sun Aug 18 04:12:55 UTC 2013
#16830: url_to_postid() doesn't resolve attachments when rewrite rules are disabled
-----------------------------+------------------------------
Reporter: Coolkevman | Owner:
Type: feature request | Status: reopened
Priority: normal | Milestone: Awaiting Review
Component: Rewrite Rules | Version: 1.2
Severity: normal | Resolution:
Keywords: needs-patch |
-----------------------------+------------------------------
Comment (by c3mdigital):
Replying to [comment:6 MikeSchinkel]:
> Replying to [comment:5 c3mdigital]:
> > I can't think of a use case for needing the attachment_id when you
have the full url to the actual image, maybe to get the attachment meta
data? I'm closing but if anyone has a use case that I'm missing please
reopen.
>
> One reason you mention is attachment meta data.
>
> Further, most ''(all?)'' of the `wp_get_attachment()` functions expect
an attachment post ID, so I can very much see how this would be useful for
more advanced WordPress development, for example to parse URLs out of user
entered content to match up with attachments or to parse the URL out of a
feed for a site that has its database on the same MySQL server as the site
with running, and to determine it's ID in the other site's database.
>
> ''(We are doing both of these on my current project.)''
>
> However, the implementation of this function needs to be more complex
than to just check against the `guid` because that can fail.
After thinking about this more I agree. I also agree that using guid is
not a good idea. I've come up with a patch that works nicely and will get
the post or attachment ID of any attachment image.
The basic premise is checking if the url has an image extension then
parsing it and extracting the string that would be save in postmeta as
`_wp_attached_file` It also checks if it is a resized image and slices out
the width x height bits.
--
Ticket URL: <http://core.trac.wordpress.org/ticket/16830#comment:9>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software
More information about the wp-trac
mailing list