From c7abf696f719ded33d6fb2138b3bb6c13f44864d Mon Sep 17 00:00:00 2001 From: gregory-p Date: Thu, 25 Apr 2019 12:04:39 +0300 Subject: [PATCH] LAW-2641 --- htdocs/wp-content/themes/lawcarta/functions.php | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/htdocs/wp-content/themes/lawcarta/functions.php b/htdocs/wp-content/themes/lawcarta/functions.php index b41aaf7..29ce403 100644 --- a/htdocs/wp-content/themes/lawcarta/functions.php +++ b/htdocs/wp-content/themes/lawcarta/functions.php @@ -175,9 +175,18 @@ function my_filter_post_where( $where) { if (!enableSearchQuery()) { return $where; } + $parts = explode(' ', trim($_POST['search_text'])); + + $likeConditions = []; + foreach($parts as $part){ + + $likeConditions [] = $wpdb->posts . '.post_title LIKE \'%' . trim(esc_sql( $part )) . '%\' '; + $likeConditions [] = $wpdb->posts . '.post_content LIKE \'%' . trim(esc_sql( $part )) . '%\' '; + + } + $where .= ' AND ( - ' . $wpdb->posts . '.post_title LIKE \'%' . esc_sql( $_POST['search_text'] ) . '%\' OR - ' . $wpdb->posts . '.post_content LIKE \'%' . esc_sql( $_POST['search_text'] ) . '%\' + '.implode(' OR ', $likeConditions) .' )'; return $where;