function query_meta($fields) { $results = array(); global $wpdb; if ($this->search_term) { $currentUser = wp_get_current_user(); $query = "SELECT ID FROM {$wpdb->users} WHERE NOT ID = '{$currentUser->ID}'"; $users = $wpdb->get_col($query); $search = $this->search_term; $fields = explode(',', $fields); foreach ($users as $user) { $userPublicName = nm_user_public_name($user); //Search the Meta foreach ($fields as $field) { $field = trim($field); $fieldData = nm_profile_info($field, $user); if (!is_array($fieldData)) { if (eregi($search, $fieldData)) { $results[] = $user; } } elseif (is_array($fieldData)) { foreach ($fieldData as $value) { if (eregi($search, $value)) { $results[] = $user; } } } } //Search the Public Name if (eregi($search, $userPublicName)) { $results[] = $user; } } } $this->user_meta_results = $results; }
function nm_members_you_should_meet($uid = 'current', $limit = '999', $matches = true, $fields = 'hometown,interests') { global $wpdb; if ($uid == 'current') { $uid = wp_get_current_user(); $uid = $uid->ID; } $fields = explode(',', $fields); //Get all the user except the current one and users friends $friendList = new userFriends(); $friends = nm_array_invert($friendList->get_friends($uid)); $friends_sql = ''; if (!empty($friends)) { foreach ($friends as $friend) { $sep = ' AND '; $friends_sql .= $sep . "ID != '" . $friend . "'"; } } $query = "SELECT ID FROM {$wpdb->users} WHERE ID != '{$uid}'" . $friends_sql; $users = $wpdb->get_col($query); $results = array(); //Loop through the users' profile info foreach ($fields as $field) { $field = trim($field); $userField = nm_profile_info($field, $uid); //Only check if the user has filled in thair profile info if ($userField != '' || !empty($userField)) { foreach ($users as $user) { $otherField = nm_profile_info($field, $user); if ($userField == $otherField && !is_array($userField)) { $results[] = $user; } elseif (is_array($userField) && is_array($otherField)) { foreach ($userField as $singleField) { foreach ($otherField as $otherSingle) { if ($otherSingle == $singleField) { $results[] = $user; } } } } } } } //Sort the array by most matches $numResults = array_count_values($results); $finalResults = array(); //Compile the final array of IDs foreach ($numResults as $key => $result) { $finalResults[] = $key; } $finalResults = array_slice($finalResults, 0, $limit); //Add random users until there are 4 matches $needed = $limit - count($finalResults); while ($needed > 0) { $randomUser = $users[array_rand($users)]; if (!in_array($randomUser, $finalResults) && $randomUser != 0) { $finalResults[] = $randomUser; $needed--; } } //Return the array of IDs return $finalResults; }