• Resolved sammyw

    (@sammyw)


    How do I save images to custom directory based on postname or posttitle. I have scraped a list of product names and image urls, i want to save all images to /uploads/{postname}/{image_1.jpg} eg: /uploads/MSIRX580/image_1.jpg

    The default method of saving 30k images on a single directory is not ideal or organised for me.

    I tried this code but WP All Import doesn’t create or save in any directory.

    function add_date_to_upload_dir( $param ) {
        
        $the_post = $_REQUEST['post_id'];
        $dir = '/' . $the_post->post_name . '/' ;
        $param['path'] = $param['path'] . $dir;
        $param['url'] = $param['url'] . $dir;
        return $param;
    }
    
    add_filter( 'upload_dir', 'add_date_to_upload_dir' );

    [Moderator note: code fixed. Please wrap code in the backtick character or use the code button.]

    • This topic was modified 7 years, 10 months ago by bdbrown.
Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter sammyw

    (@sammyw)

    This code below works great if I manual create a post and set the title first

    function add_title_to_upload_dir( $param ) {    
        $getpostid = $_REQUEST['post_id'];
        $dir = '/test/' . get_the_title($getpostid);
        $param['path'] = $param['path'] . $dir;
        $param['url'] = $param['url'] . $dir;
        return $param;
    }
    add_filter( 'upload_dir', 'add_title_to_upload_dir' );

    [Moderator note: code fixed. Please wrap code in the backtick character or use the code button.]

    But WP Import cannot get the title, i’ll only save all images on “test” directory. I’ve tried importing only the titles and description first, then updating it with images, no luck. How to change the base plugin code, kindly point me to the file which handles the title input and upload path.

    • This reply was modified 7 years, 10 months ago by bdbrown.
    Thread Starter sammyw

    (@sammyw)

    is there a way to do this?

    Plugin Author WP All Import

    (@wpallimport)

    Hi @sammyw

    I’m sorry but this isn’t currently possible and we wouldn’t be able to advise on how to edit the core plugin code.

    You might be able to find some workaround by utilizing our API ( https://www.wpallimport.com/documentation/developers/action-reference/ ) in addition to the upload_dir filter.

    • This reply was modified 7 years, 9 months ago by WP All Import.
Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Save Images to directory Postname’ is closed to new replies.