Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

In 3.4 I used the following function to change image upload folder by post type. Different upload directory based on post type in a theme Now it doesn't work anymore in 3.5. Do you have any idea how to replace this function in 3.5 version?

thanks

share|improve this question
1  
What is your research so far? What have you tried (aside from "those functions doesn't work anymore")? As you can read when hovering over the voting arrows or when you read the faq, the site expects some research from your site. –  kaiser Jan 26 '13 at 17:05

1 Answer 1

up vote 3 down vote accepted

Yes, it does. I had to do something similar just yesterday and worked out this solution. About the same as the linked solution, but with a bit more error checking.

<?php
add_filter('upload_dir', 'cgg_upload_dir');
function cgg_upload_dir($dir)
{
    // xxx Lots of $_REQUEST usage in here, not a great idea.

    // Are we where we want to be?
    if (!isset($_REQUEST['action']) || 'upload-attachment' !== $_REQUEST['action']) {
        return $dir;
    }

    // make sure we have a post ID
    if (!isset($_REQUEST['post_id'])) {
        return $dir;
    }

    // modify the path and url.
    $type = get_post_type($_REQUEST['post_id']);
    $uploads = apply_filters("{$type}_upload_directory", $type);
    $dir['path'] = path_join($dir['basedir'], $uploads);
    $dir['url'] = path_join($dir['baseurl'], $uploads);

    return $dir;
}
share|improve this answer
    
it works, thank you –  user9909 Feb 15 '13 at 16:15
    
@chrisguitarguy Tried this if($type == 'post') { $type == 'customfolderforposts'; } But no luck. Any ideas? –  INT Jun 16 at 17:10

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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