I have a lot of uploaded image files and image sizes. So it would be better to organize media files into folders based on post type. I have just read this tutorial, but as I can see it works with plugins. How to change this to use in a theme?
Thanks.
function custom_upload_directory( $args ) {
Â
    $id = $_REQUEST['post_id'];
    $parent = get_post( $id )->post_parent;
Â
    // Check the post-type of the current post
    if( "post-type" == get_post_type( $id ) || "post-type" == get_post_type( $parent ) ) {
        $args['path'] = plugin_dir_path(__FILE__) . "uploads";
        $args['url'] = plugin_dir_url(__FILE__) . "uploads";
        $args['basedir'] = plugin_dir_path(__FILE__) . "uploads";
        $args['baseurl'] = plugin_dir_url(__FILE__) . "uploads";
    }
    return $args;
}
add_filter( 'upload_dir', 'custom_upload_directory' );
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: