David C. Omeke, Esq.
John O. Chukwu, Esq.
Gabriel Ikeogu, Esq.
C.C Okonkwo, Esq.
1. Mrs. Afam-Nkwoka (Clerk)
2. Bro. Chigbo Godwin (Sexton)
function vc_search_handler() { vc_disable_caching(); $q = sanitize_text_field($_POST['query']); $user_id = get_current_user_id(); $block_usernames = get_option('vicichat_block_username_search', 'no'); global $wpdb; $post_ids = []; // --- USERNAME SEARCH LOGIC --- if (strpos($q, '@') === 0 && !preg_match('/[ +a-zA-Z0-9]@/', $q) && strpos($q, ' ') === false) { $pure_username = ltrim($q, '@'); if ($block_usernames === 'yes') { $user_exists = get_user_by('slug', $pure_username) || get_user_by('login', $pure_username); if ($user_exists) wp_send_json_error('My Gee Vicilook, searching specific usernames is restricted.'); } // Changed ID to ASC because array_reverse() is called later $sql_user = $wpdb->prepare( "SELECT p.ID FROM {$wpdb->posts} p LEFT JOIN {$wpdb->users} u ON p.post_author = u.ID WHERE p.post_status = 'publish' AND p.post_type = 'vicichats' AND (u.user_nicename = %s OR u.user_login = %s) ORDER BY p.ID ASC LIMIT 50", $pure_username, $pure_username ); $post_ids = $wpdb->get_col($sql_user); } // --- CONTENT TAG SEARCH LOGIC (STRICT RELEVANCE + PRIORITY) --- if (empty($post_ids)) { $standardized = str_replace('+', ' ', $q); $words = array_filter(explode(' ', $standardized)); $where_clauses = []; $search_terms = []; foreach ($words as $word) { $word = trim($word); if (empty($word)) continue; $clean_word = (substr(strtolower($word), -1) === 's') ? substr($word, 0, -1) : $word; $search_terms[] = $clean_word; $where_clauses[] = $wpdb->prepare("p.post_content LIKE %s", '%' . $wpdb->esc_like($clean_word) . '%'); } if (!empty($where_clauses)) { /** * THE FIX: * 1. Priority: Verified Vicilook URLs last in the initial list (Priority 2). * 2. Chronology: Oldest ID first (ID ASC). * 3. Result: After array_reverse(), the Latest Verified posts appear at the BOTTOM. */ $sql_content = "SELECT DISTINCT p.ID FROM {$wpdb->posts} p WHERE p.post_status = 'publish' AND p.post_type = 'vicichats' AND (" . implode(' AND ', $where_clauses) . ") ORDER BY CASE WHEN p.post_content LIKE '%vicilook.com/places%' THEN 2 ELSE 1 END ASC, p.ID ASC LIMIT 50"; $post_ids = $wpdb->get_col($sql_content); } } $results = []; if (!empty($post_ids)) { /** * CHAT-STYLE ORDERING: * Flips the priority group to the end and makes the newest IDs appear last. */ $post_ids = array_reverse($post_ids); foreach ($post_ids as $pid) { $post = get_post($pid); $author_id = $post->post_author; $likers = get_post_meta($pid, '_vici_heart_user_ids', true) ?: []; $user_liked = is_array($likers) && in_array($user_id, $likers); $results[] = [ 'user' => '@' . get_the_author_meta('user_nicename', $author_id), 'content' => (string)vicichat_format_content($post->post_content), 'time' => get_the_time('M j, Y g:i A', $pid), 'hearts' => (int)get_post_meta($pid, '_vici_heart_count', true) ?: 0, 'id' => $pid, 'user_liked' => $user_liked, 'can_delete' => vc_can_user_delete($post, $user_id) ]; } } wp_send_json_success(array_values($results)); }
David C. Omeke, Esq.
John O. Chukwu, Esq.
Gabriel Ikeogu, Esq.
C.C Okonkwo, Esq.
1. Mrs. Afam-Nkwoka (Clerk)
2. Bro. Chigbo Godwin (Sexton)