From: Steve Sutton Date: Tue, 19 Jun 2018 13:16:51 +0000 (-0400) Subject: Update wmta member search X-Git-Tag: v1.0.29^2~3 X-Git-Url: http://cvs2.gaslightmedia.com/gitweb/index.cgi?a=commitdiff_plain;h=450a3ff03783febef12f96b4a4c30ef4b861363d;p=WP-Themes%2Fwmta.git Update wmta member search Break out words in the search and use each one for match. --- diff --git a/functions.php b/functions.php index d8554de..e30951d 100644 --- a/functions.php +++ b/functions.php @@ -411,25 +411,42 @@ function new_mail_from_name($old) { add_filter('glm-member-db-front-search-query', function( $queryParts ){ if ( isset( $_REQUEST['s'] ) && $_REQUEST['s'] ) { $textSearch = addslashes(filter_var($_REQUEST['s'], FILTER_SANITIZE_STRING, FILTER_FLAG_NO_ENCODE_QUOTES)); - $queryParts[] = " ( + // Split the search by spaces + $sub_parts = explode( ' ', $textSearch ); + $name_part = $desc_part = $city_part = array(); + foreach ( $sub_parts as $part ) { + $name_part[] = " name SOUNDS LIKE '%$part%' OR name LIKE '%$part%'"; + $desc_part[] = " T.descr SOUNDS LIKE '%$part%' OR T.descr LIKE '%$part%'"; + $city_part[] = " name SOUNDS LIKE '%$part%' OR name LIKE '%$part%'"; + } + // echo '
$sub_parts: ' . print_r( $sub_parts, true ) . '
'; + $query_parts = " ( ( SELECT true FROM ".GLM_MEMBERS_PLUGIN_DB_PREFIX."members WHERE id = T.member - AND ( - name SOUNDS LIKE '%$textSearch%' - OR name LIKE '%$textSearch%' - ) - ) - OR T.descr SOUNDS LIKE '%$textSearch%' - OR T.descr LIKE '%$textSearch%' - OR T.city IN ( + AND ("; + if ( $name_part ) { + $query_parts .= implode( ' OR ', $name_part ); + } + $query_parts .= ") + ) OR "; + if ( $desc_part ) { + $query_parts .= implode( ' OR ', $desc_part ); + } + $query_parts .= "OR T.city IN ( SELECT id FROM " . GLM_MEMBERS_PLUGIN_DB_PREFIX . "cities - WHERE name SOUNDS LIKE '%$textSearch%' - OR name LIKE '%$textSearch%' - ) - )"; + WHERE "; + if ( $city_part ) { + $query_parts .= implode( ' OR ', $city_part ); + } + // $query_parts .= " name SOUNDS LIKE '%$textSearch%' OR name LIKE '%$textSearch%'"; + + $query_parts .= ") + )"; + $queryParts[] = $query_parts; } + // echo '
$queryParts: ' . print_r( $queryParts, true ) . '
'; return $queryParts; });