Skip to content

Instantly share code, notes, and snippets.

@mustafauysal
Created December 7, 2013 17:37
Show Gist options
  • Save mustafauysal/7845879 to your computer and use it in GitHub Desktop.
Save mustafauysal/7845879 to your computer and use it in GitHub Desktop.
Change WordPress upload_dir per post type.
<?php
/**
* Change upload dir for video post type
* Media files that comes from video post type will be stored under
* wp-content/uploads/video/year/month/file-name.blah
* use "upload_dir" filter
* @param $args
* @return mixed
*/
public function video_upload_directory( $args ) {
$id = $_REQUEST['post_id'];
$parent = get_post( $id )->post_parent;
$video_dir = "/videos";
// Check the post-type
if ( "video" == get_post_type( $id ) || "video" == get_post_type( $parent ) ) {
$args['subdir'] = $video_dir . $args['subdir'];
$args['path'] = $args['basedir'] . $args['subdir'];
$args['url'] = $args['baseurl'] . $args['subdir'];
}
return $args;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment