• Resolved helppawz1

    (@helppawz1)


    I have some code that is using attachment_url_to_postid to find the post id from an image url that is uploaded via a form. The problem is when a large image is uploaded, or an image with orientation data is uploaded. WordPress then adds -scaled or -rotated to the file name so that attachment_url_to_postid no longer works. I’ve found a way to stop the images being scaled, but not a way to stop them being rotated. Is this possible? Or is it possible to find the post ID from the original image url?

Viewing 2 replies - 1 through 2 (of 2 total)
  • Moderator bcworkz

    (@bcworkz)

    The original filename does not exist in the DB, so there’s no 100% reliable way to relate it to an attachment ID. By default, WP assigns the filename (without extension) as the attachment title. As long as that has not been altered, you could query for attachment posts with the filename as title.

    Or arbitrarily insert “-rotated” into the original filename before attempting to get the attachment ID.

    I don’t know if there’s a way to prevent rotation. TBH it doesn’t sound like a good idea anyway ??

    Thread Starter helppawz1

    (@helppawz1)

    Thank you for the ideas. I have managed to solve the problem using get_page_by_title.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘find post id of attachement even if -scaled or -rotated is added to file name’ is closed to new replies.