function find_person_from_search_text($search_text) { $api_key = defined('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') ? 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 : ''; if (!$api_key || empty($search_text)) { return null; } // Get candidate names from WordPress. // Change 'person' to your actual custom post type. $people = get_posts([ 'post_type' => 'person', 'post_status' => 'publish', 'posts_per_page' => 100, ]); if (empty($people)) { return null; } $candidates = []; foreach ($people as $person) { $candidates[] = [ 'id' => $person->ID, 'name' => get_the_title($person->ID), ]; } $prompt = "Find the person from this search text. Search text: {$search_text} Candidate people: " . wp_json_encode($candidates) . " Return ONLY the ID of the best matching person. If none of the candidates are a reasonable match, return 0."; $response = wp_remote_post('https://api.openai.com/v1/responses', [ 'headers' => [ 'Authorization' => 'Bearer ' . $api_key, 'Content-Type' => 'application/json', ], 'body' => wp_json_encode([ 'model' => 'gpt-5.6', 'input' => $prompt, ]), 'timeout' => 30, ]); if (is_wp_error($response)) { return null; } $body = json_decode( wp_remote_retrieve_body($response), true ); $result = trim($body['output'][0]['content'][0]['text'] ?? ''); $person_id = absint($result); if (!$person_id) { return null; } return get_the_title($person_id); } https://www.qgp.com/post-sitemap.xml 2026-03-03T10:51:42+00:00 https://www.qgp.com/page-sitemap.xml 2026-02-14T04:49:50+00:00 https://www.qgp.com/team-sitemap.xml 2026-07-10T00:48:51+00:00 https://www.qgp.com/product-sitemap.xml 2026-07-30T13:47:56+00:00 https://www.qgp.com/faq-sitemap.xml 2022-01-17T15:58:45+00:00 https://www.qgp.com/category-sitemap.xml 2026-03-03T10:51:42+00:00 https://www.qgp.com/team_designation-sitemap.xml 2026-07-10T00:48:51+00:00 https://www.qgp.com/team_department-sitemap.xml 2026-07-10T00:48:51+00:00 https://www.qgp.com/product_cat-sitemap.xml 2026-07-30T13:47:56+00:00 https://www.qgp.com/commission_cat-sitemap.xml 2024-09-14T10:14:00+00:00 https://www.qgp.com/wpm-testimonial-category-sitemap.xml 2025-09-26T18:23:29+00:00 https://www.qgp.com/author-sitemap.xml 2026-02-12T07:43:21+00:00