[wp-hackers] automatic image importing
otto at ottodestruct.com
Sun Sep 23 11:36:25 UTC 2012
On Sun, Sep 23, 2012 at 5:28 AM, Abdussamad Abdurrazzaq
<abdussamad at abdussamad.com> wrote:
> There are some functions in wp-admin/includes/file.php and media.php that
> you can use:
> download_url() to download the file
> media_handle_sideload() to add the file to media library
> Then wp_insert_post to add a new post with wp_get_attachment_link() as the
The function you actually want to use is media_sideload_image(), which
does this all in one step.
So basically, create your normal post, then call
media_sideload_image() to download the image, create the attachment
post, and attach it to the parent post ID.
More information about the wp-hackers