WordPress Plugin Development: How do I find out the attachment ID from a url of an uploaded media file?
-
I'd like to delete a file in the Media Library. It seems the http://codex.wordpress.org/Function_Reference/wp_delete_attachment function needs to be used for the task and it requires an attachment ID. When I only know the url of a file, is it possible to retrieve the attachment ID fromĀ the url? As I searched the web, I found the following code but I always get the $results variable empty. $query = "SELECT ID FROM wp_posts where guid = '" . esc_url($image_url) . "' AND post_type = 'attachment'"; $results = $wpdb -> get_results($query); foreach ( $results as $row ) { wp_delete_attachment( $row -> ID ); }
-
Answer:
Anonymous at Quora Visit the source
Related Q & A:
- How can I find a Yahoo user ID if I only have the name?Best solution by Yahoo! Answers
- How do I change my my Yahoo ID to a different name, but still have the same account?Best solution by Yahoo! Answers
- How can I find a person`s Yahoo ID just by name and place?Best solution by in.answers.yahoo.com
- How can I find Yahoo email address with only a full name?Best solution by Yahoo! Answers
- How can I find out my local temperature on a past day?Best solution by wunderground.com
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.