Last active
August 29, 2015 14:07
-
-
Save eccentricpixel/c8ac4a7534facb51aa4c to your computer and use it in GitHub Desktop.
Upgrade of Wordpress' media search function to find matches in the filename which is stored in the GUID column. In the end, a much more user-friendly (client-friendly) experience. Works with modal select windows too (ex: add media buttons).
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
/* Upgrade the Media search to allow for searching the filename. | |
* =========================================================== */ | |
add_filter( 'posts_search', 'guid_search_media', 10, 2 ); | |
function guid_search_media( $search, $a_wp_query ) | |
{ | |
global $wpdb, $pagenow; | |
// Only Admin side && Only Media Library page | |
if ( !is_admin() && 'upload.php' != $pagenow ) | |
return $search; | |
// Original search string: | |
$search = str_replace( | |
'AND ((', | |
'AND (((' . $wpdb->prefix . 'posts.guid LIKE \'%' . $a_wp_query->query_vars['s'] . '%\') OR ', | |
$search | |
); | |
return $search; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment