I am working on my first script to create a WP post with images and upload those images to the uploads folder.
I am clear about wp_insert_post
and was able to upload an image to the server with wp_handle_upload
, but what do I do after it's uploaded to create all its resized versions (for responsive design) and add all the relevant metadata info to the database?
Also do I need wp_media_upload_handler
(since it takes no parameters) and, if so, how/when do I run that in relation to wp_handle_upload?
media_handle_upload()
which automatically creates the resized versions.add_image_size()
including standard sizes such as thumbnail and 'medium' - see the Media Settings admin screen. And yes, the function does create the metadata; seewp_generate_attachment_metadata()
andwp_update_attachment_metadata()
in the "Uses" section here.