Hi,
I need to customize the search of the gallery. I've got the script for this, is already working on wp-admin/upload.php, but I need to also work in the search for media gallery. Anyone have any idea to solve this?
Follows the code I'm using:
function atom_search_where($where, $query){
global $wpdb;
//if we are not on admin or the current search is not on attachment return
if(!is_admin() || (!isset($query->query['post_type']) || $query->query['post_type'] != 'attachment'))
return $where;
// if current query is the main query and a search...
if( is_main_query() && is_search() )
{
// explictly search post_tag taxonomies
$where .= "OR (post_type = 'attachment' AND t.name LIKE '%".get_search_query()."%')";
}
return $where;
}
function atom_search_join( $join, $query){
global $wpdb;
//if we are not on admin or the current search is not on attachment return
if(!is_admin() || (!isset($query->query['post_type']) || $query->query['post_type'] != 'attachment'))
return $join;
// if current query is the main query and a search...
if( is_main_query() && is_search() )
{
$join .= "INNER JOIN {$wpdb->term_relationships} tr ON {$wpdb->posts}.ID = tr.object_id INNER JOIN {$wpdb->term_taxonomy} tt ON tt.term_taxonomy_id=tr.term_taxonomy_id INNER JOIN {$wpdb->terms} t ON t.term_id = tt.term_id";
}
return $join;
}
add_filter('posts_where','atom_search_where', 10, 2 );
add_filter('posts_join', 'atom_search_join', 10, 2 );
Sorry my english