[wp-hackers] automatic image importing
Dmitry Tokmakov
dmitry at getmoxied.net
Tue Sep 25 02:12:12 UTC 2012
Thanks a lot guys! your information saved me a lot of time and minimized my code!
It didnt work for me until I included this modules:
require_once(ABSPATH . "wp-admin" . '/includes/media.php');
require_once(ABSPATH . "wp-admin" . '/includes/file.php');
require_once(ABSPATH . "wp-admin" . '/includes/image.php');
Thank you!
Dmitry
getmoxied.net
On Sep 23, 2012, at 3:36 PM, Otto wrote:
> 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
>> content.
>
> 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.
>
> -Otto
>
> -Otto
> _______________________________________________
> wp-hackers mailing list
> wp-hackers at lists.automattic.com
> http://lists.automattic.com/mailman/listinfo/wp-hackers
More information about the wp-hackers
mailing list