How to limit Woocommerce search to titles only?

I used to have a snippet that limits search results to titles only, but with recent updates it doesn't work any mor

I used to have a snippet that limits search results to titles only, but with recent updates it doesn't work any more. It will be great it of somebody can help here out, for me and others that looking for a solution to this. Thanks D

EDIT: That's the old code:

// Search by Title only!
function __search_by_title_only( $search, &$wp_query )
{
    global $wpdb;
    if(empty($search)) {
        return $search; // skip processing - no search term in query
    }
    $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;
}
add_filter('posts_search', '__search_by_title_only', 500, 2);

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745331095a4622880.html

相关推荐

  • How to limit Woocommerce search to titles only?

    I used to have a snippet that limits search results to titles only, but with recent updates it doesn't work any mor

    6小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信