How to open a file in external editor programmatically in eclipse plugin development?

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

Was this solution helpful to you?

Just Added Q & A:

Find solution

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.