由于PHP版本的问题,我们有些朋友可能开启的兼容不报错,所以我们有些问题看不出来。但是随着日志的增加会占用服务器磁盘,看到PHP日志有提示"search_by_title_only() expected to be a reference"问题,如何解决呢?
// PHP报错问题 by laozuo.org
add_filter('posts_search', 'laozuoorg_search_by_title_only', 500, 2);
function laozuoorg_search_by_title_only($search) {
global $wpdb, $wp_query;
if (empty($search))
return $search;
$q = $wp_query->query_vars;
$n = !empty($q['exact']) ? '' : '%';
$search =
$searchand = '';
foreach ((array) $q['search_terms'] as $term) {
$term = esc_sql($wpdb->esc_like($term));
$search .= "{$searchand}($wpdb->posts.post_title LIKE '{$n}{$term}{$n}')";
$searchand = ' AND ';
}
if (!empty($search)) {
$search = " AND ({$search}) ";
if (!is_user_logged_in())
$search .= " AND ($wpdb->posts.post_password = '') ";
}
return $search;
}