I've been trying to implement a custom search that won't only search posts but also media (by they're titles and custom fields).
Before going for the whole thing, I performed a little test: I wanted the search to display only posts of type 'attachment'(media) and I thought I could achieve this by putting the following piece of code in my functions.php:
function SearchFilter($query) {
if ($query->is_search) {
$query->set('post_type', 'attachment');
$query->set('post_status', 'inherit');
$query->set('post_parent', NULL);
}
return $query;
}
add_filter('pre_get_posts','SearchFilter');
Unfortunately, no luck. When searching it doesn't display the (unattached) media files. Any idea what might be wrong?