Custom Upload Path by Post Type
-
How would I go about setting S3 upload file paths based off of post type?
It seems like this approach is a good starting point, but I haven’t been able to make it work, perhaps the tag i’m trying to hook into is wrong :
https://www.ads-software.com/support/topic/custom-upload-path-by-file-typeHere’s my code:
function wp_update_attachment_metadata_s3( $data, $post_id ) { global $post; $type = get_post_type( $post->ID ); $path = ''; $post_types = array( 'project', 'post', 'page' ); switch ($type) { case 'project': $path = 'project'; break; default: $path = 'default'; break; } if ( $path ) { add_filter( 'as3cf_setting_object-prefix','dynamic_path_'.$path, 10,1 ); } return $data; } function dynamic_path_project( $value ) { return 'project'; } function dynamic_path_default( $value ) { // set up upload/year/month path $t = date('m Y'); $time = explode(" ", $t); $month = $time[0]; $year = $time[1]; return 'uploads/' . $year . '/' . $month; } add_filter( 'wp_update_attachment_metadata','wp_update_attachment_metadata_s3', 20, 2 );
Thanks
https://www.ads-software.com/plugins/amazon-s3-and-cloudfront/
- The topic ‘Custom Upload Path by Post Type’ is closed to new replies.