[ad_1]
function exclude_img_file_name_from_search($query) {
if (is_search()) {
$meta_query = (array)$query->get(‘meta_query’);
$meta_query[] = array(
‘key’ => ‘_wp_attached_file’,
‘value’ => ‘test_file_name’,
‘compare’ => ‘NOT LIKE’,
);
$query->set(‘meta_query’, $meta_query);
}
}
I have modified the search function with the above code. When I change \`compare\` value to ‘NOT LIKE’, ‘LIKE’, ‘!=’, ‘=’, … none of them work. It always shows empty search result regarding any search term.
[ad_2]