为什么WP_Query的's'=>'关键字'仅搜索'post_title',为什么不搜索'post_content'?

时间:2016-11-26 06:11:04

标签: php wordpress search

我正在为自定义帖子编写搜索查询。我正在使用WP_Query的搜索参数,然后它必须搜索'post_title'和& 'post_content'但它只搜索'post_title'而不是搜索'post_content'。下面是我的代码:

 $institute_name = get_user_meta($user_ID, 'inistitute_name', true);
 add_filter( 'posts_where' , array($this,'posts_where' ));
 $paged = (get_query_var('page')) ? get_query_var('page') : 1;
         $args = array(
            'post_type' => 'mypost',
            array( 's' => $keyword ),
            'meta_query' => array (
                array (
                  'key' => 'inistitute_name',
                  'value' => array ($institute_name),
                  'compare' => 'IN'
                )
            ),
            'posts_per_page' => -1,
            'paged' => $paged,
            'post_status' => 'publish',
            );
$the_query = new WP_Query($args);
remove_filter( 'posts_where',  array($this,'posts_where' ));
echo "<pre>";
print_r($the_query);
echo "</pre>";

如果我打印出该结果,那么我将收到如下查询:

SELECT wp_dxwe_posts.* FROM wp_dxwe_posts INNER JOIN wp_dxwe_postmeta ON 
( wp_dxwe_posts.ID = wp_dxwe_postmeta.post_id ) WHERE 1=1  AND 
( (wp_dxwe_postmeta.meta_key = 'inistitute_name' AND 
CAST(wp_dxwe_postmeta.meta_value AS CHAR) IN ('ITeLearn') )) 
AND wp_dxwe_posts.post_type = 'mypost' AND ((wp_dxwe_posts.post_status = 'publish')) 
AND post_title LIKE '%launch%' GROUP BY wp_dxwe_posts.ID 
ORDER BY wp_dxwe_posts.post_date DESC 

正如我所说,它仅适用于'post_title',但为什么它不能用于'post_content'。谁能告诉我这段代码有什么问题?提前谢谢。

1 个答案:

答案 0 :(得分:0)

如果没有正确的全文索引,搜索整个机构的速度会太慢,在较大的网站上,这可能最终会降低服务器性能。