How do you find a file in the media library using the file URL?

Based on my research, you would need to run a query on directly on the database using WPDB. So you would do something like this: Add this in your functions.php file: // retrieves the attachment ID from the file URL function get_image_id($image_url) { global $wpdb; $the_attachment = $wpdb->get_col($wpdb->prepare(“SELECT ID FROM $wpdb->posts WHERE guid=’%s’;”, $image_url )); … Read more

Filter media library by custom postmeta

I had to implement the following: Change the admin UI to include my custom filters add_action(‘wp_enqueue_media’, function () { wp_enqueue_script(‘media-library-taxonomy-filter’, get_stylesheet_directory_uri() . ‘/assets/js/custom-media-filter.js’, array(‘media-editor’, ‘media-views’)); }); In the custom-media-filter.js I am appending the custom select HTML and every time my custom select is changed, add the query parameters in the URL and redirect with this … Read more