I am currently setup a custom post type with a custom meta box for file uploading in posts. Based on this tutorial, I am able to upload the file with wp_upload_bits()
function, which is something like this:
wp_upload_bits($_FILES['wp_custom_attachment']['name'], null, file_get_contents($_FILES['wp_custom_attachment']['tmp_name']));
The problem is that I am unable to create the subfolders in uploads folder base on each custom post type automatically. When the file is uploaded, it is either organized by years and months or dumped in uploads
folder (if I go to Settings > Media and uncheck “Organize my uploads into month- and year-based folders.)
Notes
Based on this article about attachments in WordPress, it seems that one can work around this by bypassing WordPress built-in API.
Is there any other ways for this?