// ==================================================== // PHASE 1: FAQ検索 (CPT + ACF対応版) // ==================================================== $faq_query = new WP_Query( array( 'post_type' => 'gyoda_faq', // CPT UIで作ったスラッグ 's' => $search_keywords, 'posts_per_page' => 1, 'post_status' => 'publish', )); if ( $faq_query->have_posts() ) { $faq_query->the_post(); // 【最良のポイント】 // ACFで 'chat_answer' というフィールドを作っておき、 // チャット専用の短い回答があればそれを優先、なければ本文を丸めて使う $chat_answer = get_field('chat_answer'); if ( !empty($chat_answer) ) { $reply = $chat_answer; } else { // 本文からタグを除去して使用 $reply = wp_strip_all_tags( get_the_content() ); // 改行コードの調整等は必要に応じて } $reply .= "\n\n詳しくはこちらを見るのじゃ: " . get_permalink(); wp_reset_postdata(); return new WP_REST_Response( array( 'reply' => $reply, 'source' => 'faq' ), 200 ); }