本机搜索页面运行如下查询:
SELECT SQL_CALC_FOUND_ROWS wp_posts.*
FROM wp_posts
WHERE 1=1 AND (((wp_posts.post_title LIKE \'%keyword%\')
OR (wp_posts.post_content LIKE \'%keyword%\'))
AND (wp_posts.post_password = \'\')
AND wp_posts.post_type IN (\'post\', \'page\', \'attachment\')
AND (wp_posts.post_status = \'publish\')
ORDER BY wp_posts.post_date DESC LIMIT 0, 10
我通过挂接到pre\\u get\\u帖子来向查询传递特定的帖子ID,因此我不需要其他帖子
WHERE
与关键字相关的条件。e、 g。
add_filter(\'pre_get_posts\',\'my_search_filter\');
function my_search_filter($query) {
if ($query->is_search) {
// post IDs within distance X
$matches = array(1,3,5);
$query->query_vars[\'post__in\'] = $matches;
}
}
如何通过修改现有查询而不是编写新查询,从查询对象中删除与post\\u title和post\\u内容相关的条件。