简体   繁体   English

为什么WP_Query的's'=>'keyword'只搜索'post_title',为什么不搜索'post_content'?

[英]Why WP_Query's 's'=>'keyword' searches only for 'post_title' and why not 'post_content'?

I am writing a search query for my custom post. 我正在为我的自定义帖子编写搜索查询。 I am using search parameter of WP_Query for this then it has to search for both 'post_title' & 'post_content' but it is searching only for 'post_title' and not searching the 'post_content'. 我为此使用WP_Query的搜索参数,然后它必须同时搜索“ post_title”和“ post_content”,但它仅搜索“ post_title”而不搜索“ post_content”。 below is my code : 下面是我的代码:

 $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>";

If I print that result then I am getting the query like below: 如果我打印该结果,则得到如下查询:

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 

As I said it is working fine for only 'post_title' but why it is not working for 'post_content'. 正如我说的那样,它仅适用于“ post_title”,但为何不适用于“ post_content”。 Can anyone please tell me what's wrong in this code? 谁能告诉我这段代码有什么问题吗? Thanks in advance. 提前致谢。

没有适当的全文索引,搜索整个实体的速度将太慢,以至于扩展到在较大的站点上,这最终可能会降低服务器的性能。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM