• Resolved LPackman

    (@furnituresuppliesuk)


    Hello,

    Is it possible to import images from a live site to a staging site whilst also keeping the original folder structure.

    For example images originally inside /wp-content/uploads/2020/06/ after importing become /wp-content/uploads/2021/03/ obviously these images would lose any image SEO.

    I hope there is a simple solution.

    Thank you in advance for your help and also for this great timesaving plugin!

Viewing 1 replies (of 1 total)
  • Plugin Author WP All Import

    (@wpallimport)

    Hi @furnituresuppliesuk,

    Is it possible to import images from a live site to a staging site whilst also keeping the original folder structure.

    At this time, that would require custom code and our wp_all_import_images_uploads_dir hook: https://www.wpallimport.com/documentation/advanced/action-reference/#wp_all_import_images_uploads_dir.

    Here is an example snippet that you can modify as needed:

    /**
     * Upload all images for the post to a folder based on the post date (in Y/m format)
     *
     * (e.g. if the post was published on June 1st 2017, its images would
     *  be uploaded to /wp-content/uploads/2017/06)
     *
     */
     
    function wpai_set_upload_folder_by_post_date($uploads, $articleData, $current_xml_node, $import_id) {
    	if ( ! empty($articleData['post_date'])) {
    		$uploads['path'] = $uploads['basedir'] . '/' . date("Y/m", strtotime($articleData['post_date']));
    		$uploads['url'] = $uploads['baseurl'] . '/' . date("Y/m", strtotime($articleData['post_date']));
    		
    		if (!file_exists($uploads['path'])) {
    			mkdir($uploads['path'], 0755, true);
    		}
    	}
    	return $uploads;
    }
    
    add_filter('wp_all_import_images_uploads_dir', 'wpai_set_upload_folder_by_post_date', 10, 4);
Viewing 1 replies (of 1 total)
  • The topic ‘Importing images whilst keeping original folder structure’ is closed to new replies.