When an image is imported, the name used in the media library is derived from the URL "basename". This can cause problems, especially when using the option "Search through the Media Library for existing images before importing new images". For example, even though they are different images, these URLs all have the same "basename" (in bold). They will generate the same file my-image.jpg
in the WordPress library:
http:// example.com/ my-image.jpg
http:// example.com/ my-image?id=1
http:// example.com/subfolder/ my-image.jpg
The solution is to put this PHP code in your function editor:
function fix_img_url($url){
return empty($url) ? "" : $url."#/".substr(md5($url),0,8).".jpg";
}
And put the following in your image field, substituting the correct field name for {image[1]}:
[fix_img_url({image[1]})]
This forces WP All Import to generate an image name derived from the entire URL instead of just the basename.
Here is a function I wrote - it basically takes the id and url and creates an MD5 hash and uses that as the filename. You pass between 2 and 3 parameters, the id, the url and limit (limit is a number to limit the amount of images processed for the property):
function fix_img_urls($urls,$propref,$limit=null) {
if (is_null($limit)) { $limit=999;}
$output = array();
$separator = ","; // Change this to your separator character
$curim=1;
foreach (explode($separator,$urls) as $url) {
$url = trim($url);
if ($curim <= $limit) {
$output[] = empty($url) ? "" : $url."#/".substr(md5($url),0,8).$propref.".jpg";
}
$curim++;
}
return implode(",",$output);
}