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;