Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save propertyhive/99788e07880d5090bf7a5d89da2efdd3 to your computer and use it in GitHub Desktop.
Save propertyhive/99788e07880d5090bf7a5d89da2efdd3 to your computer and use it in GitHub Desktop.
Put property media into it's own uploads directory
function custom_upload_dir($uploads) {
if (isset($_REQUEST['post_id'])) {
$post_id = (int) $_REQUEST['post_id'];
$post = get_post($post_id);
if ($post && $post->post_type == 'property') {
$subdir = '/property';
// Modify the upload directory paths
$uploads['subdir'] = $subdir;
$uploads['path'] = $uploads['basedir'] . $subdir;
$uploads['url'] = $uploads['baseurl'] . $subdir;
}
}
return $uploads;
}
add_filter('upload_dir', 'custom_upload_dir');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment