Using “media_handle_sideload” to upload images programmatically does not upload image to Media Library

Your failing and getting a WP_Error object returned before the function runs wp_insert_attachment().

You should always include a check for is_wp_error( $thing ) when calling a function that returns WP_Errors.

$result = media_handle_sideload($array, $id);

if ( ! is_wp_error( $result ) ) {
   return $result;
} else {
   var_dump( $result->get_error_messages );
 }

Your problem will be listed in the output of error messages

Leave a Comment