How to Get URL of a Post's/Page's "Featured Image"?


Are there any easy ways to determine the URL of a Page or Post’s Featured Image if you have its ID ?

I’m looking to directly query the database with PHP to do some more fancy tricks with my design, but I’m dead stuck on getting the location of Featured Image (resized version).

Are there any good plugins out there for this, or quick tricks?

Thanks a lot.


[FONT=“Georgia”]Incidentally, I’d started writing a slightly long block of PHP that bounced between the wp_posts and wp_postmeta tables to determine the URL of featured images, but got stuck at that insane syntax for the “_wp_attachment_metadata” meta_key.

If there are any guides to extracting data out of that mess, that would be one possible solution for me. I’m guessing that would be a REGEX of some kind?


if(has_post_thumbnail()) {
     $feature_image = get_the_post_thumbnail($post->ID, 'thumbnail'); 

I can’t recall if there’s a specific function to just return the image URL - the one above returns the img element. You could use regex to parse it. Or you could use:

$feature_image_id = get_post_thumbnail_id($id);
$feature_image_meta = wp_get_attachment_image_src($feature_image_id, '32')

[FONT=“Georgia”]Thanks. Wow, that’s certainly shorter than the code I was creating.

I’ll try it out later.


[FONT=“Georgia”]Thanks again, timothytrice.

It’s working perfectly :tup: