I'm trying to upload some media to the media library in a "uploads" subfolder. The problem is that the media is added, I can see a new entry in the media library, the database the guid of the file give the right path but in the wp-admin all the thumbnails are linked to files in the root of uploads.
Is there any way to tell WP to generate thumbnails in the subfolder ? Or Am I doing something wrong ?
Here is the code I use :
$guid = $upload_path['url'] . '/subfolder/' . $filename; $path = $upload_path['path']."/subfolder/".$filename; $attachment = array( 'guid' => $guid, 'post_mime_type' => $wp_filetype['type'], 'post_title' => preg_replace('/\.[^.]+$/', '', sprintf(__('%s\'s file'),$current_user->user_login ) ), 'post_content' => '', 'post_status' => 'inherit' ); $attach_id = wp_insert_attachment( $attachment, $filename, 0 ); require_once(ABSPATH . 'wp-admin/includes/image.php'); $attach_data = wp_generate_attachment_metadata( $attach_id, $path ); wp_update_attachment_metadata( $attach_id, $attach_data );
I would like to achieve that without a plugin.
Thank you !