0

I'm trying upload certain files to the following custom director:

/wp-content/uploads/audio/yyyy/mm

However, the year and month directories are not being created properly. They are showing up like this:

/wp-content/uploads/audio/%25year%25/%25month%25/

Here is the code that I'm trying to make this work with.

function custom_upload_directory( $path ) {

$id = $_REQUEST['post_id'];
$parent = get_post( $id )->post_parent;

// Check the post-type of the current post
if( "risen_multimedia" == get_post_type( $id ) || "risen_multimedia" == get_post_type( $parent ) ) {

$customdir = "/audio";

    $time = current_time( 'mysql' );
    $y = substr( $time, 0, 4 );
    $m = substr( $time, 5, 2 );
    $subdirectory = "/$y/$m";

$path['path']    = str_replace($path['subdir'], '', $path['path']); //remove default subdir (year/month)
$path['url']     = str_replace($path['subdir'], '', $path['url']);      
$path['subdir']  = $customdir . $subdirectory;
$path['path']   .= $path['basedir'] . $customdir . $subdirectory;
$path['url']    .= $path['baseurl'] . $customdir . $subdirectory;
return $path;
}
return $path;
}
add_filter( 'upload_dir', 'custom_upload_directory' );

So I'm not sure why the year and month are showing up as words with % signs around them instead of integers?

0

Can't test at the moment but I'd try rewriting the date to variable code from:

$time = current_time( 'mysql' );
$y = substr( $time, 0, 4 );
$m = substr( $time, 5, 2 );
$subdirectory = "/$y/$m";

To:

$y = date('Y');
$m = date('m');
$subdirectory = "/" . $y . "/" . $m;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.