Make WordPress Core

Opened 11 years ago

Closed 10 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: wiltave Owned by:
Milestone: Priority: normal
Severity: normal Version: 3.1
Component: General Keywords:
Focuses: Cc:


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)

patch.diff (1.0 KB) - added by wiltave 11 years ago.

Download all attachments as: .zip

Change History (5)

11 years ago

#1 @andrewryno
11 years ago

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.

#2 @wiltave
11 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 @andrewryno
11 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.

#4 @SergeyBiryukov
10 years ago

  • Milestone Awaiting Review deleted
  • Resolution set to wontfix
  • Status changed from new to closed

As andrewryno pointed out, similar functions already exist.

Note: See TracTickets for help on using tickets.