WP get attachment ID from image url

1
2
<?php
// retrieves the attachment ID from the file URL
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Credit: Pippin https://pippinsplugins.com/retrieve-attachment-id-from-image-url/

Note: I am not a fan of direct DB calls to non-index columns but I needed this once and found it short and simple.

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.