默认搜索由处理WP_Query
主要是通过一个名为parse_search()
, 由s
参数您可以搜索WP_Query
对于is_search
把其他一些零碎的东西拼凑在一起。
或者您可以创建一个查询。。。
$s = new WP_Query(array(\'s\' => \'test\'));
。。。转储SQL。。。
var_dump($s->request);
。。。并阅读它。
SELECT SQL_CALC_FOUND_ROWS wp_posts.ID
FROM wp_posts
WHERE 1=1
AND (((wp_posts.post_title LIKE \'%test%\')
OR (wp_posts.post_content LIKE \'%test%\')))
AND (wp_posts.post_password = \'\')
AND wp_posts.post_type IN (\'post\',
\'page\',
\'attachment\',
\'book\')
AND (wp_posts.post_status = \'publish\')
ORDER BY wp_posts.post_date DESC LIMIT 0,2
您应该看到,默认情况下
LIKE
查询标题和内容。“句子”搜索被分解如下:
AND (((wp_posts.post_title LIKE \'%Hello%\')
OR (wp_posts.post_content LIKE \'%Hello%\'))
AND ((wp_posts.post_title LIKE \'%I%\')
OR (wp_posts.post_content LIKE \'%I%\'))
AND ((wp_posts.post_title LIKE \'%am%\')
OR (wp_posts.post_content LIKE \'%am%\'))
AND ((wp_posts.post_title LIKE \'%a%\')
OR (wp_posts.post_content LIKE \'%a%\'))
AND ((wp_posts.post_title LIKE \'%test%\')
OR (wp_posts.post_content LIKE \'%test%\')))