Hi @helppawz1
You are right, I completely missed the “-rotated” part, probably because it’s not as common as -scaled.
But the “attachmant_url_to_postid” returns 0 if it cannot find attachment so I think we can benefit from that and just search for “-scaled” and “-rotated” versions of images.
Try replacing this part of the code
foreach ($fields_data as $key=>$single_field) {
if ($single_field['key'] === $acfgal) {
$images = explode( ',', $single_field['value'] );
foreach ($images as $a=>$b) {
$theimages[$a]=attachment_url_to_postid( trim($b) );
}
update_post_meta( $post_id, $acfgal, $theimages );
}
}
with this:
foreach ($fields_data as $key=>$single_field) {
if ($single_field['key'] === $acfgal) {
$images = explode( ',', $single_field['value'] );
foreach ($images as $a=>$b) {
$single_image = trim($b);
$single_image_ext = '.' . preg_match('/\./', $single_image) ? preg_replace('/^.*\./', '', $single_image) : '';
$theimages[$a]=attachment_url_to_postid( $single_image );
if ( $theimages[$a] == 0 ) {
$single_image_scaled = str_ireplace( $single_image_ext, '-scaled'.$single_image_ext, $single_image );
$theimages[$a] = attachment_url_to_postid( $single_image_scaled );
}
if ( $theimages[$a] == 0 ) {
$single_image_rotated = str_ireplace( $single_image_ext, '-rotated'.$single_image_ext, $single_image );
$theimages[$a] = attachment_url_to_postid( $single_image_rotated );
}
}
update_post_meta( $post_id, $acfgal, $theimages );
}
}
Best regards,
Adam