I am having trouble uploading an image with the WordPress REST API (WP-API). Can someone provide some sample code. Basically I have an image that I got from a service and I’m showing in an <img>
tag. Now I need to take that image and save it in the media library using javascript.
Alternatively (not using WP-API) if there is a plugin that would do that, I can pass the url for the image to get is saved in the media library.
Thanks
You can use the
wp_insert_attachment
if API is not preferred. SourceIgnore the
$parent_post_id
if the media library is not post specific.You can retrieve the image url using this trick: Retrieve images and then use the variable for
$filename