Last active
December 17, 2015 11:28
-
-
Save thejamescollins/5602011 to your computer and use it in GitHub Desktop.
attachment_url_to_postid() Simple Example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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