Opened 14 years ago
Closed 14 years ago
#17017 closed feature request (wontfix)
Check if a post has a featured image and get its URL (outside from the_loop)
Reported by: |
|
Owned by: | |
---|---|---|---|
Milestone: | Priority: | normal | |
Severity: | normal | Version: | 3.1 |
Component: | General | Keywords: | |
Focuses: | Cc: |
Description
I get posts with get_posts. I didn't find a way to check, outside of the_loop, if a post has a featured image and how to get its URL (for example, wp-content/uploads/month/featured-image.ext).
I've made two functions, please, take a look at the attachment. I've put it in wp-includes/post.php. Maybe you could improve it (if it needs) and include to the core.
Attachments (1)
Change History (5)
#2
@
14 years ago
Sorry about has_post_thumbnail. It worked. I haven't tried the "hacky" solution, but what about a simple function call instead of a "hacky"? I still suggest a function for that because a simple function call would be better for themes.
Thank you very much andrewryno.
#3
@
14 years ago
That may have been a poor choice of word on my part. That is the way it should be done by using those functions. It's just a little more than one function. wp_get_attachment_url()/wp_get_attachment_image_src() is used the way it should be, as well as the_post_thumbnail(). I don't see the point of having to add another function just to get the URL when there is already a function to do that. That's my opinion, though.
Have you tried http://codex.wordpress.org/Function_Reference/has_post_thumbnail and http://wordpress.org/support/topic/getting-post-thumbnail-url? First function takes a post ID parameter, and while the second is "hacky", it works as required.