[wp-trac] [WordPress Trac] #16830: url_to_postid() doesn't resolve attachments when rewrite rules are disabled

WordPress Trac wp-trac at lists.automattic.com
Thu Mar 17 14:08:22 UTC 2011


#16830: url_to_postid() doesn't resolve attachments when rewrite rules are disabled
---------------------------+------------------------------
 Reporter:  Coolkevman     |       Owner:
     Type:  defect (bug)   |      Status:  new
 Priority:  normal         |   Milestone:  Awaiting Review
Component:  Rewrite Rules  |     Version:  3.1
 Severity:  normal         |  Resolution:
 Keywords:                 |
---------------------------+------------------------------

Comment (by Coolkevman):

 FYI, this [http://wordpress.org/support/topic/need-to-get-attachment-id-
 by-image-url issue emerged from a forum topic].

 There [http://wordpress.org/support/topic/need-to-get-attachment-id-by-
 image-url#post-1943754 you'll find a solution] under the form of a custom
 method:
 {{{
 function get_attachment_id_from_src ($image_src) {
   global $wpdb;
   $query = "SELECT ID FROM {$wpdb->posts} WHERE guid='$image_src'";
   $id = $wpdb->get_var($query);
   return $id;
 }
 }}}

 The code above may be tightly integrated to {{{url_to_postid()}}} to solve
 image URLs to post IDs.

-- 
Ticket URL: <http://core.trac.wordpress.org/ticket/16830#comment:1>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software


More information about the wp-trac mailing list