这可以通过以下方式更改搜索查询:posts_search
钩
http://core.trac.wordpress.org/browser/tags/3.3.1/wp-includes/query.php#L2202
默认搜索查询如下所示:
..AND (((wp_posts.post_title LIKE \\\'%search terms%\\\') OR (wp_posts.post_content LIKE \\\'%search terms%\\\')))
我们需要删除帖子内容搜索,一个正则表达式就足够了。
add_filter( \'posts_search\', \'wpse_45153_filter_search\', null, 2 );
function wpse_45153_filter_search( $search, $a_wp_query ) {
if ( !is_admin() ) return $search; // work only in the dashboard
$search = preg_replace( "# OR \\(.*posts\\.post_content LIKE \\\\\'%.*%\\\\\'\\)#", "", $search );
return $search;
}
请注意,正则表达式尚未经过彻底测试,当其他插件或主题将钩子改为此处时,可能会出现边缘情况。