I have a custom post type of ‘clients’ and would like all images/files uploaded through the admin for these posts to go to a specific directory on my server, but everything else to stay as normal. Is this possible maybe using wp_upload_dir?
Leave a Reply
You must be logged in to post a comment.
You can add a filter to upload_dir. Here is a simple class I wrote to do this for a project. Use the
protected $filter_path
variable to define the alternate uploads directory (*will be relative to wp-content/uploads)Usage:
The prefix_upload_dir_filter function would need to be attached to an action or filter with the $post object available or the $post ID. You will need to do some more research to figure this part out or maybe someone else can chime in. My usage was a complete custom image upload solution from the front end where I needed the publicly uploded images placed in a temp directory that could be cleaned out nightly via a cron job.
Something like this may do the trick, just change mycpt as you like
This works quite well: