Changeset 29029 for trunk/src/wp-includes/media.php
- Timestamp:
- 07/08/2014 05:47:53 PM (11 years ago)
- File:
-
- 1 edited
-
trunk/src/wp-includes/media.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/media.php
r28976 r29029 3219 3219 } 3220 3220 } 3221 3222 /** 3223 * Try to convert an attachment URL into a post ID. 3224 * 3225 * @since 4.0.0 3226 * 3227 * @global wpdb $wpdb WordPress database access abstraction object. 3228 * @param string $url The URL to resolve. 3229 * @return int The found post_id. 3230 */ 3231 function attachment_url_to_postid( $url ) { 3232 global $wpdb; 3233 3234 $dir = wp_upload_dir(); 3235 $path = ltrim( $url, $dir['baseurl'] . '/' ); 3236 3237 $sql = $wpdb->prepare( 3238 "SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_wp_attached_file' AND meta_value = %s", 3239 $path 3240 ); 3241 $post_id = $wpdb->get_var( $sql ); 3242 if ( ! empty( $post_id ) ) { 3243 return (int) $post_id; 3244 } 3245 }
Note: See TracChangeset
for help on using the changeset viewer.