How do I get attachment_id?

Ok, all those hipercomplex functions can be reduced to one simple command: attachment_url_to_postid

You only need to parse the image url to retrieve the attachment id:

<?php

   $attachment_id = attachment_url_to_postid( $image_url );
   echo $attachment_id;

?>

That’s all you need.

Leave a Comment