Skip to content

Instantly share code, notes, and snippets.

@schalkjoubert
Created January 24, 2018 06:31
Show Gist options
  • Save schalkjoubert/18d4ff87c7b7de01cafff0fe6ebf655b to your computer and use it in GitHub Desktop.
Save schalkjoubert/18d4ff87c7b7de01cafff0fe6ebf655b to your computer and use it in GitHub Desktop.
<?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