Created
January 24, 2018 06:31
-
-
Save schalkjoubert/18d4ff87c7b7de01cafff0fe6ebf655b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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