php、Wordpress初心者です。
WordPressで英語、韓国語、中国語簡体字、中国語繁体字の計4言語のサイトを構築しています。
検索窓を設置したのですが、韓国語と中国語繁体字の2言語で検索結果が反映されない状況です。
serach.php
php
1<?php 2 global $wp_query; 3 $total_results = $wp_query->found_posts; 4 $search_query = get_search_query(); 5?> 6 7<?php 8 if( $total_results >0 ): 9 if ( have_posts() ) : ?> 10 11 <h2 class="page-title">搜索: <?php the_search_query(); ?></h2> 12 <?php while ( have_posts() ) : the_post(); ?> 13 <a href="<?php the_permalink() ?>"> 14 <?php 15 $postImage = getPostImage($post); 16 if($postImage == null){ 17 ?> 18 <img src="<?php bloginfo('template_directory');?>/img/noimage.png" alt=""> 19 <?php 20 }else{ 21 echo '<img src="'.$postImage["url"].'" class="alignright" alt="'.$postImage["alt"].'" />'; 22 } 23 24 ?> 25 </a> 26 27 <?php the_title( sprintf( '<h3 class="h3_search"><a href="%s" rel="bookmark">', esc_url( get_permalink() ) ), '</a></h3>' ); ?> 28 <p><?php 29 $descr = mb_substr(get_the_excerpt(), 0, 400); 30 $descr = mb_substr(strip_tags(my_noshotcode($post-> post_content)),0,90); 31 $descr = strip_tags($descr, '<br>'); 32 echo $descr; 33 ?>...<a href="<?php the_permalink() ?>" class="arrow">more</a></p> 34 35<? endwhile; endif; 36else : ?> 37 <h2>Not Found</h2> 38<? endif; ?>
ただし、韓国語と中国語繁体字でも、英語で入力すると正しい検索結果が得られます。
【サイトについて】
英語、韓国語、中国語簡体字、中国語繁体字、それぞれ別にドメインを取得し、
それぞれにWordpressを設置しています。databaseも別です。
サーバーは下記のように分かれています。
英語 CPIサーバー 文字コード:utf8
韓国語 CPIサーバー 文字コード:utf8
中国語簡体字 PEGASUS 文字コード:utf8 ※define('DB_COLLATE', 'utf8_unicode_ci');
中国語繁体字 CPIサーバー 文字コード:utf8
【検索したときのパラメータ】
例)景點(景色)という単語で検索
/?s=景點&x=8&y=19
【検索結果のmeta title】
搜索 ?Ŀ? ←「景點」の文字化け??
【WordPress】
PHP 5.2.8
バージョン 4.8.5
テーマ 自作
検索窓 コード(中国語繁体字)
php
1<div class="search"> 2 <form method="get" id="searchform" action="<?php echo esc_url( home_url( '/' ) ); ?>" /> 3 <input type="text" name="s" class="search-box" placeholder="檢索" /> 4 <input type="image" src="<?php echo esc_url( home_url() ); ?>/wp-content/uploads/2018/03/search.png" alt="Search" value="<?php echo $_GET['s']; ?>" class="search-btn" /> 5 </form> 6</div>
【試したこと】
・一般設定の言語切り替え(日本語だったのを、それぞれの言語へ)
・プラグイン「WP Multibyte Patch」を有効化
・Wordpressデバッグモード⇒ functions.phpにあるereg()のエラーがでていました
・ウィジェットの検索窓で検索
【予測したこと】
・文字コードが関係しているのではと仮説を立てています。
あなたの回答
tips
プレビュー