[英]Replace [keyword] in post_content with words from post_title MYSQL
[英]Why WP_Query's 's'=>'keyword' searches only for 'post_title' and why not 'post_content'?
我正在为我的自定义帖子编写搜索查询。 我为此使用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”。 谁能告诉我这段代码有什么问题吗? 提前致谢。
没有适当的全文索引,搜索整个实体的速度将太慢,以至于扩展到在较大的站点上,这最终可能会降低服务器的性能。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.