I have developed custom post type in Wordpress, and besides other I am trying to process and display images on every post page.
When I set multiple image html fields, ie
<input type="file" name="an_uploaded_attachment" id="multiUpload" />
<input type="file" name="an_uploaded_attachment" id="multiUpload" />
and submit post, images are normaly displayed on post page. But when I include mutiple file upload like
<input type="file" name="an_uploaded_attachment" id="multiUpload" multiple />
images are not processed.
This is what I am using for registering images in WP:
if (!function_exists('wp_generate_attachment_metadata')){
require_once(ABSPATH . "wp-admin" . '/includes/image.php');
require_once(ABSPATH . "wp-admin" . '/includes/file.php');
require_once(ABSPATH . "wp-admin" . '/includes/media.php');
}
//if ($_FILES) {
foreach ($_FILES as $file => $array) {
if ($_FILES[$file]['error'] !== UPLOAD_ERR_OK) {
return "upload error : " . $_FILES[$file]['error'];
}
$attach_id = media_handle_upload( $file, $post_id );
update_post_meta($post_id,'_thumbnail_id',$attach_id);
}
Does anyone knows something about this? Tried few scripts but they dont work.