Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I'm trying to create a custom form which takes an image (offsite) and attaches it to the post so I can use it as a thumbnail in the loop. I've been looking at media_handle_upload but that appears to only be working for content that's locally uploaded.

Ideas?

Thanks, Dennis

share|improve this question

1 Answer 1

up vote 1 down vote accepted

When you link to an external image, WordPress will reference the external URL. media_handle_upload is meant to handle uploaded images that are now living on your server. So unless you're telling the server to download the image from the external source and save it on your server, media_handle_upload won't apply.

It sounds like you're building your own custom importer. I recommend you take a deeper look at the process. A typical upload:

  • User selects file from local system
  • File uploads through form to $_POST variable
  • WordPress takes file out of POSTed form, runs it through media_handle_upload, and stores it on the server

If you're referencing an offsite image and attaching it to the post, WordPress won't do steps 2 and 3. You'll need to add your own scripts to grab the remote image and store a copy locally.

share|improve this answer
    
Thanks, but the user won't select a file from local system, it will be a url provided by a custom field :) –  FLX Jun 9 '11 at 22:18
    
That's what I'm trying to tell you. If you're putting a URL in a custom field, you aren't actually uploading anything. WordPress only runs media_handle_upload on uploaded media. So if you want to use the offsite image in the loop as a thumbnail, you need to make your plugin fetch the image and store it locally on the server following the same path a file would take if the user were to upload it directly. –  EAMann Jun 10 '11 at 14:14
    
Thanks EAMann, it appears media_sideload_image exists though, which should be able to perform this. I haven't been able to get it to work, but I asked a question about it here. I would really appreciate it if you could take a look :) Thanks! –  FLX Jun 12 '11 at 21:04

Your Answer

 
discard

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.