Okay. I solved it by myself. i dunno what’s wrong, but it looks like using first case – just doesn’t work. using second case – is a bad idea.
so i began to work with sql and posts_where commands.
first: instead of $wp_query->query_vars['s']
i started to use get_search_query()
second: looks like when sql tries to compare meta_value with value, it asks for %
. yes, so in sql code you should write something like:
wp_postmeta.meta_key LIKE \'_entitle\' AND wp_postmeta.meta_value LIKE \'%' . get_search_query() . '%\'
third: because you are using wp_postmeta, you must join its posts ids with ids from wp_posts:
function dasdasd( $join, $query ) {
global $wpdb;
if ( is_search() ) {
$join = 'INNER JOIN wp_postmeta ON ( wp_posts.ID = wp_postmeta.post_id )';
}
return $join;
}
add_filter('posts_join', 'dasdasd', 10, 2 );
and fourth: i dunno why but you must add groupby code:
add_filter( 'posts_groupby', 'adadad', 10, 2 );
function adadad( $groupby, $query ){
$groupby = 'wp_posts.ID';
return $groupby;
}
i would like to know what’s wrong with fourth step and why groupby’s existing is so important for search query. thank you.