Skip to content

Instantly share code, notes, and snippets.

@om4james
Last active December 17, 2015 11:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save om4james/5602011 to your computer and use it in GitHub Desktop.
Save om4james/5602011 to your computer and use it in GitHub Desktop.
attachment_url_to_postid() Simple Example
<?php
$attachment_id = attachment_url_to_postid( 'http://yourdomain.com/wp-content/uploads/myfile.pdf' );
if ( $attachment_id ) {
// This file was found in the WordPress media library
// In this example we are going to permanently delete this file from the WordPress media library.
// Please be careful if you are copying/pasting this example code!
wp_delete_attachment( $attachment_id, true );
} else {
// This file wasn't found in the WordPress media library
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment