WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Given a Vimeo ID, I can retrieve a thumbnail from the video via Vimeo Simple API. Rather than call the API every time my page loads I want to set the image as the post thumbnail using the save_post hook (similar to this question).

My problem is that I am not familiar with URL calls in php. I would like to know:

  1. the benefits/drawbacks of using a method like curl compared to WP_Http. Is one "better" than the other?

  2. the order in which I should call functions to successfully set the post thumbnail.

Any help would be greatly appreciated.

share|improve this question
Has anyone figured this out? I'm trying to do this as well. – user4086 Mar 20 '11 at 17:42
up vote 9 down vote accepted

My favorite way of handling this problem has been to use a little documented function I discovered on another stack post: media_sideload_image

It works by fetching an image url to the WordPress upload dir and then associating the image to a post's attachments.

You can try it like so:

// required libraries for media_sideload_image
require_once(ABSPATH . 'wp-admin/includes/file.php');
require_once(ABSPATH . 'wp-admin/includes/media.php');
require_once(ABSPATH . 'wp-admin/includes/image.php');

// $post_id == the post you want the image to be attached to
// $video_thumb_url == the vimeo video's thumb url
// $description == optional description

// load the image
$result = media_sideload_image($video_thumb_url, $description);

// then find the last image added to the post attachments
$attachments = get_posts(array('numberposts' => '1', 'post_parent' => $post_id, 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => 'ASC'));

if(sizeof($attachments) > 0){
    // set image as the post thumbnail
    set_post_thumbnail($post_id, $attachments[0]->ID);
share|improve this answer
Nice. This looks promising. – Dan Gayle Nov 30 '11 at 1:16
Just worked. Thx... – somatic Feb 26 '12 at 20:28

Hi @David John Smith:

1.) If you are in WordPress, (almost) always use WP_Http; it's one of the many things I love about working with WordPress. Why call it and not CURL? Well, because it has a nicer syntax and it calls CURL if CURL is available. If not, it chooses from one of 3 other options. So it really is a brilliant piece of kit.

2.) To answer the 2nd question I'll need to know how you want to name the files you are downloading?

share|improve this answer
Thanks Mike. As for the post thumbnails, I don't really care how they're named, I would just like to be able to access them as related to a post, either by post_thumbnail() or get_post_meta(). I guess it would make sense to name it with the post ID. – David John Smith Oct 20 '10 at 2:45
any update on this? – NetConstructor.com Nov 5 '10 at 15:20
@NetConstructor - It's really hard to keep track of questions that are in a "pending" state, so no. I just created a "pending" folder on my bookmarks bar, I'll see if I can't be more consistent with that. But, I don't have time right now for this one so will have to come back to it. – MikeSchinkel Nov 5 '10 at 23:08
@Mike -- thanks Mike, just thought you might have had a solution here cause among other things you seem to be the master of this stuff :-) – NetConstructor.com Nov 5 '10 at 23:47
@NetConstructor.com - LOL! Thanks, I'm just master of the debugger, that is all. :) – MikeSchinkel Nov 5 '10 at 23:51

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.