Bạn hãy thêm đoạn code sau vào file functions.php

add_filter('posts_search','tmdev_custom_search_wordpress', 500, 2);
function tmdev_custom_search_wordpress( $search, $wp_query )
    {
        global $wpdb;
        if ( empty( $search ) )
            return $search;
        $q = $wp_query->query_vars;    
        $n = ! empty( $q['exact'] ) ? '' : '%';
        $n = '';

        $search = $searchand = '';
        
        $term_post_content = implode(" ", $q['search_terms']);
        $term_post_content = esc_sql( like_escape( $term_post_content ) );

        foreach ( (array) $q['search_terms'] as $key1 => $term ) {
            $term = esc_sql( like_escape( $term ) );
            if( $key1 == 0 ){
                $term = $term.'-';
            }
            if( $key1 > 0 ){
                $term = '-'.$term;
            }
            $search .= "{$searchand}($wpdb->posts.post_name REGEXP '{$n}{$term}{$n}')";
            $searchand = ' AND ';
        }    

        $search .= " OR ($wpdb->posts.post_content REGEXP '{$n}{$term_post_content}{$n}')";

        if ( ! empty( $search ) ) {
            $search = " AND ({$search}) ";
            if ( ! is_user_logged_in() )
                $search .= " AND ($wpdb->posts.post_password = '') ";
        }
        
        return $search;
}

 

Bài viết liên quan

post-no-image

Chia sẻ một số thư viện loading css đẹp

giai-phap-chinh-css-khong-bi-luu-cache-trinh-duyet

Giải pháp tốt khi chỉnh sửa css mà không sợ bị lưu cache trình duyệt

post-no-image

Một số css tùy biến thẻ input type: select, number

post-no-image

Tắt lazyload cho một số hình ảnh

post-no-image

Tuỳ biến layout YITH WooCommerce Wishlist

post-no-image

Một số hook hoặc filter thường sử dụng trong plugin WPML