WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am using Add From Server plugin http://wordpress.org/extend/plugins/add-from-server/ basically it imports/upload image from the server. Currently the plugin copies the images into month/year folder format but I want to change it by making it copy by the Post ID folder format instead of month/year.

I have already tried using the Custom Upload Dir plugin but it doesn't work with Add From Server plugin together. Can anyone tweak Add From Server plugin to make it upload by Post ID?

share|improve this question
up vote 1 down vote accepted

You can try to add this into your functions.php file:

add_filter( 'upload_dir','wpse87234_upload_dir');
function wpse87234_upload_dir($uploads){

    // check if we are in the "Add From Server" media tab
    if (isset($_REQUEST['post_id']) && isset($_GET['tab']) && $_GET['tab']=="server") {

        // change the uploads info to our needs:
    return $uploads;    

This should give directory like /wp-content/uploads/post_1234/ with post_id 1234.

share|improve this answer


From the plugins source: it uses wp_upload_dir() and wp_insert_attachment(), which uses update_attached_file(). So basically the plugin should just incorporate your media settings. If it is not doing this, it has a conflict with either some other plugin, or your wp-config.php settings.

Filter callback for the rescue

You can still use the 'upload_dir'-filter. It takes one argument that has the following data:

    'path'    => $dir,
    'url'     => $url,
    'subdir'  => $subdir,
    'basedir' => $basedir,
    'baseurl' => $baseurl,
    'error'   => false,

Just add a callback to it:

add_filter( 'upload_dir', 'wpse87234_custom_upload_dir' );
function wpse87234_custom_upload_dir( $data )
    // Change everything you need.
    return array_merge( $data, array(
        'path'    => $data['dir'],
        'url'     => $data['url'],
        'subdir'  => $data['subdir'],
        'basedir' => $data['basedir'],
        'baseurl' => $data['baseurl'],
        'error'   => false,
    ) );
share|improve this answer

Your Answer


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.