I try to set up a custom upload directory for just product images.
I use this code to create the folder 'product' in the uploads directory
function fcsp_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', 'fcsp_type_upload_dir' );
(Is from Different upload directory based on post type in a theme)
The directory is created fine but how can I get it right so it will store the product images in it?
I tried it with:
define( 'UPLOADS', trailingslashit( WP_CONTENT_DIR ) . '$args' );
The images, however, are still uploaded to the default upload directory i.e. /uploads/2019/01
. What am I missing?
I try to set up a custom upload directory for just product images.
I use this code to create the folder 'product' in the uploads directory
function fcsp_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', 'fcsp_type_upload_dir' );
(Is from Different upload directory based on post type in a theme)
The directory is created fine but how can I get it right so it will store the product images in it?
I tried it with:
define( 'UPLOADS', trailingslashit( WP_CONTENT_DIR ) . '$args' );
The images, however, are still uploaded to the default upload directory i.e. /uploads/2019/01
. What am I missing?
1 Answer
Reset to default -2$uploads = wp_upload_dir();
$uploads['basedir'].'/product/' /**** uplode product directory path ***/
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745285881a4620557.html
/uploads/2019/01
to/uploads/product
. Was just thinking: I'm using the Media Cloud plugin to upload the images also to Amazon S3. In the end I just want to remove the uploaded images form the WordPress install after the upload to S3 is done. I can't remove them with the setting in the plugin because some mapping functions have to run first. – A3O Commented Jan 21, 2019 at 9:23