专注云服务商活动
网站运营运维笔记

解决网站出现"search_by_title_only() expected to be a reference"问题

由于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;
}

 

投上你的一票
域名主机商优惠信息推送QQ群: 627775477 获取商家优惠推送,禁言。
赞(0)
未经允许不得转载:老左笔记 » 解决网站出现"search_by_title_only() expected to be a reference"问题