Title: Get image ID from path
Last modified: August 19, 2016

---

# Get image ID from path

 *  [Justin](https://wordpress.org/support/users/instantok/)
 * (@instantok)
 * [16 years, 6 months ago](https://wordpress.org/support/topic/get-image-id-from-path/)
 * Hello. I’m trying to use WP attachment/image functions to manipulate images whose
   paths I get from a custom field. I need to retrieve the ID for each image based
   on this path. I’m assuming I need to write a SQL query but I don’t have the expertise.
   Can anyone give me a hand or some direction?

Viewing 2 replies - 1 through 2 (of 2 total)

 *  [Hnrrrch](https://wordpress.org/support/users/hnrrrch/)
 * (@hnrrrch)
 * [15 years, 10 months ago](https://wordpress.org/support/topic/get-image-id-from-path/#post-1257396)
 * If you want to get the image attachment id’s from all your posts, then your SQL
   would be like this:
 * `SELECT ID FROM 'wp_posts' WHERE post_type = 'attachment' AND post_mime_type 
   LIKE 'image/%'`
 *  [indyjones48](https://wordpress.org/support/users/indyjones48/)
 * (@indyjones48)
 * [15 years, 8 months ago](https://wordpress.org/support/topic/get-image-id-from-path/#post-1257405)
 * Posting just for anyone looking for an answer. Each post, images and other attachments
   included, has an associated GUID that is its complete URL path. So, just pull
   the “post” with the associated GUID:
 * **SELECT id FROM wp_posts WHERE guid = ‘[http://myblogdomain.com/full-path-to-image.jpg&#8217](http://myblogdomain.com/full-path-to-image.jpg&#8217);**

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Get image ID from path’ is closed to new replies.

## Tags

 * [custom field](https://wordpress.org/support/topic-tag/custom-field/)
 * [image](https://wordpress.org/support/topic-tag/image/)
 * [thumbnail](https://wordpress.org/support/topic-tag/thumbnail/)

 * 2 replies
 * 3 participants
 * Last reply from: [indyjones48](https://wordpress.org/support/users/indyjones48/)
 * Last activity: [15 years, 8 months ago](https://wordpress.org/support/topic/get-image-id-from-path/#post-1257405)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
