This commit is contained in:
gregory-p
2019-04-25 12:04:39 +03:00
parent 8995b05e71
commit c7abf696f7

View File

@@ -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;