Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
<?php
if(!empty( $_REQUEST["post_id"]) ) {
add_filter('upload_dir', 'tsum_upload_dir');
$upload = wp_upload_dir();
// remove_filter('upload_dir', 'tsum_upload_dir');
function tsum_upload_dir( $upload ) {
$id = $_REQUEST['post_id'];
$parent = get_post( $id )->post_parent;
// Check the post-type of the current post
if( "post-type-name-ie-product" == get_post_type( $id ) || "post-type-name-ie-product" == get_post_type( $parent ) )
$upload['subdir'] = '/replace-this-with folder-name' . $upload['subdir'];
$upload['path'] = $upload['basedir'] . $upload['subdir'];
$upload['url'] = $upload['baseurl'] . $upload['subdir'];
return $upload;
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.