修改主题目录下 fun/base/fun.Install.php
文件,
将文件中的这个代码删除掉,如下代码
// 搜索插件
array(
'name' => 'Search Everything',
'slug' => 'search-everything',
'source' => 'https://downloads.wordpress.org/plugin/search-everything.8.1.9.zip',
'required' => true,
'version' => '8.1.9',
'force_activation' => true,
'force_deactivation' => false,
),
修改主题目录下 fun/base/fun.search.php
文件
将这个文件中的所有代码替换成如下代码
<?php
/**
* 判断页面是否为页面
* @return boolean [description]
*/
function is_type_page_mi() { // Check if the current post is a page
global $post;
if ($post->post_type == 'page') {
return true;
} else {
return false;
}
}
//提高搜索结果相关性
if(is_search()){
add_filter('posts_orderby_request', 'search_orderby_filter');
}
function search_orderby_filter($orderby = ''){
global $wpdb;
$keyword = $wpdb->prepare($_REQUEST['s']);
return "((CASE WHEN {$wpdb->posts}.post_title LIKE '%{$keyword}%' THEN 2 ELSE 0 END) + (CASE WHEN {$wpdb->posts}.meta_value LIKE '%{$keyword}%' THEN 1 ELSE 0 END)) DESC,
{$wpdb->posts}.post_modified DESC, {$wpdb->posts}.ID ASC";
}
/**
* 设置搜索文章类型
* @param [type] $query [description]
* @return [type] [description]
*/
function search_filter_page($query) {
if ($query->is_search) {
$query->set('post_type', 'movie_bt');
}
return $query;
}
add_filter('pre_get_posts','search_filter_page');
/**
* 搜索时 关联postmeta表
* @param [type] $join [description]
* @return [type] [description]
*/
function mi_search_join( $join ) {
global $wpdb;
if ( is_search() ) {
$join .=' LEFT JOIN '.$wpdb->postmeta. ' ON '. $wpdb->posts . '.ID = ' . $wpdb->postmeta . '.post_id ';
}
return $join;
}
add_filter('posts_join', 'mi_search_join' );
/**
* 修改查询语句
* @param [type] $where [description]
* @return [type] [description]
*/
function mi_search_where( $where ) {
global $pagenow, $wpdb;
// var_dump($where);
if ( is_search() ) {
$where = preg_replace("/\sOR\s\(\s*".$wpdb->posts.".post_content\s+LIKE\s*(\'[^\']+\')\s*\)/", "", $where );//剔除文章内容搜索
$where = preg_replace("/\sOR\s\(\s*".$wpdb->posts.".post_excerpt\s+LIKE\s*(\'[^\']+\')\s*\)/", "", $where );//剔除摘要搜索
$where = preg_replace("/\(\s*".$wpdb->posts.".post_title\s+LIKE\s*(\'[^\']+\')\s*\)/","(".$wpdb->posts.".post_title LIKE $1) OR (".$wpdb->postmeta.".meta_value LIKE $1 AND ".$wpdb->postmeta.".meta_key IN ('performer_mi_value','aliases_mi_value','english_name_mi_value','imdb_mi_value','scenarist_mi_value','Director_mi_value'))", $where );
}
return $where;
}
add_filter( 'posts_where', 'mi_search_where');
/**
* 搜索结果去重
* @param [type] $where [description]
* @return [type] [description]
*/
function mi_search_distinct( $where ) {
global $wpdb;
if ( is_search() ) {
return "DISTINCT";
}
return $where;
}
add_filter( 'posts_distinct', 'mi_search_distinct' );