Does ‘_wp_attached_file’ meta key available in search function?

[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]

 

This site will teach you how to build a WordPress website for beginners. We will cover everything from installing WordPress to adding pages, posts, and images to your site. You will learn how to customize your site with themes and plugins, as well as how to market your site online.

Buy WordPress Transfer