0

I have custom post type and I would like that when admin/user uploads images (for example featured image) to this custom post type, the image would be uploaded to custom folder. As default they go wp-content/uploads/ but I would want them to go wp-content/uploads-post-type-name or wp-content/mu-plugins/my-plugin/uploads/

Got it done

  • No one knows? :/ – user995317 Sep 28 '15 at 18:28
  • Be patient please, ppl on this forum aint on (your) payroll, and maybe there is one who knows a solution but has not found time already to help you out. I for example am reading this just now while passing by :) and know about a plugin (which you could find yourself also in the repository) but to have a function by hand is some else. And (only) advising a plugin is not done here. – Charles Oct 1 '15 at 18:14
1

Use something like this function, you need to set condition for if(user==admin) and then if(post-type=='some-post-type'):

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 = '/' . 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' );

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.