0

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?

3
  • Try media_handle_upload() which automatically creates the resized versions.
    – Sally CJ
    Commented Jun 2, 2020 at 13:45
  • thank you @SallyCJ - is it automatic or do I have to tell it what sizes to create? and will this function also create database metadata and other relevant database entries?
    – marcnyc
    Commented Jun 2, 2020 at 17:52
  • It uses the image sizes registered via 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; see wp_generate_attachment_metadata() and wp_update_attachment_metadata() in the "Uses" section here.
    – Sally CJ
    Commented Jun 3, 2020 at 2:59

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.