If i understand your question right you want a function within your theme that adds directories for the current post_type? like: uploads/post_type_name. if so here is a function for that:
function wpse_16722_type_upload_dir( $args ) {
// Get the current post_id
$id = ( isset( $_REQUEST['post_id'] ) ? $_REQUEST['post_id'] : '' );
if( $id ) {
// Set the new path depends on current post_type
$newdir="https://wordpress.stackexchange.com/" . get_post_type( $id );
$args['path'] = str_replace( $args['subdir'], '', $args['path'] ); //remove default subdir
$args['url'] = str_replace( $args['subdir'], '', $args['url'] );
$args['subdir'] = $newdir;
$args['path'] .= $newdir;
$args['url'] .= $newdir;
}
return $args;
}
add_filter( 'upload_dir', 'wpse_16722_type_upload_dir' );
Related Posts:
- Post type specific upload folder in 3.5
- Why “Store uploads in this folder” option is not showing in Media Settings in WordPress
- wp.media add context
- Resize the WP media Uploader iFrame
- Can I stop wordpress generating media sizes
- Display attachments by the ID of the post being edited in the wp.media frame (frontend)
- One step picture upload
- How to change format of file link ( Name ) when insert from media uploder
- Set different max upload size limits based on file type/extension
- Efficient way to move media folder to another folder
- How to display the maximum upload size in a WordPress single site?
- wordpress 3.6 media manager cropping timestamp
- How i can upload images to another folder?
- Plupload Intergration in a meta-box?
- Trigger refresh for new media manager in 3.5
- Physical organization of wordpress media library (Real Media Library plugin)
- Can I upload media to a specific folder?
- wp_upload_dir how to get just the directory name .
- How to generate thumbnails when needed only?
- Limit image upload to one and disable audio, video and other document file types to upload
- How to add new tab to media upload manager with custom set of images?
- No Thumbnails Generated
- Media files exist in upload folder but not showing up
- How to Require a Minimum Image Dimension for Uploading?
- How to upload files straight to S3 without using local storage? [closed]
- Extend Media Library
- How does WP media uploader create the 3 different sized images, and how can I duplicate it
- How to make “Upload files”selected by default in Insert Media?
- WordPress 3.5: Setting custom “full URL path to files” in the Media Library?
- Get $image_id after uploading with media_sideload_image()
- simple solution for restricting access to (some) uploads/downloads
- what happens to existing media files when I switch to year/month directory structure format?
- Reject upload of wrong-sized images using the Media Uploader
- WordPress Media Uploader events
- How to delete resized (cropped) image uploads and prevent future resizing?
- How to show all available images in WP’s media library when using the Polylang plugin?
- how to upload and allow downloads of .mobi and .epub formats
- Upload post thumbnail from the front end
- Allowing WebP uploads?
- Give users a maximum upload capacity; limit the number of files a user can upload OR limit the number of files per upload
- How to add a custom field to the media screen (image/gallery)?
- Can’t upload media, permissions are correct
- How to assign multiple file-mime-types to extension?
- Saving Media – Which Hook is Fired?
- Set limit to media upload?
- Is it possible to reorganize the WordPress uploads directory?
- WordPress 3.5: Switch back to Old Media Uploader?
- Save camera info as metadata on image upload?
- Media upload finished hook
- Users can’t upload images on frontend if they haven’t got access to the wp backend
- How to upload SVG in WordPress 4.9.8?
- How Can I Organize the Uploads Folder by Slug (or ID, or FileType, or Author)?
- How can I batch delete all unattached images with WP-CLI or other automated process?
- Create image formats with different qualities when uploading
- Rename files during upload using variables
- upload_async.php returns 500 error
- Which filters or actions to use after a media upload and delete?
- Organize uploads by year, month and day
- wp_delete_attachment doesn’t delete images in wp-content/uploads/
- Display attachments by ID in a wp.media frame
- Force WordPress 3.3 to use Flash uploader
- Use a separate custom table (not posts) to handle file upload data
- Upload folder is not writable, even when permissions are correct
- Media not actually deleted on disk when click “Permanent Delete”
- Image upload callback in new 3.5 media
- retrieve custom image sizes from media uploader javascript object
- Add inline uploader to plugin option page
- Protecting direct access to PDF and ZIP unless user logged in (without plugin)
- How to wp_upload_bits() to a sub-folder?
- Using same directory for storing all uploaded images on a WordPress network
- Insert images to post not working
- Is it possible to allow zip files to be uploaded in WordPress?
- How to restrict images in v3.5 Media Library modal to only those from a specific post id?
- Allow CSV files to be uploaded
- Contact Form 7 – process form using a PHP script, instead of mailing [closed]
- Get an uploaded attachments local server path?
- How to add more upload directories?
- Change WordPress upload path and URL
- Could a large quantity of files in the uploads folder affect performance?
- PNG with transparent background turns black when uploaded and resized
- “Add Media” only shows “Full Size” under Attachment Display Settings
- Differentiate Featured Image from Post Images upon Upload
- WP 3.3 > Still no option to enable automatic image overwrites?
- Where do the favicons for Media Files come from
- How are the year and month folders added to the uploads directory?
- Where does wordpress store the FTP credentials?
- WP 3.5 media manager – how to create a working gallery frame
- Custom upload directory per CPT; when removed, file not deleted
- What might cause a POST to wp-admin/async-upload.php to return JSON >and< HTML?
- How to manage a standalone media folder?
- Send attachments via wp_mail from temporary folder
- Modify featured image path to Amazon S3
- wp_generate_attachment_metadata returns empty array
- How to set an upload directory for each media type?
- Saving images from Gravity Forms repeatable File Upload as post attachments [closed]
- How do I link directly to uploaded files?
- Large Uploads in WordPress
- Is it possible to trigger some JavaScript when Media Popup is opened?
- How to call WP3.5 Media Library manager?
- Disable media library tab for non admins in uploader screen