フォーラムへの返信

7件の返信を表示中 - 1 - 7件目 (全7件中)
  • フォーラム: 使い方全般
    返信が含まれるトピック: サイト内検索で記事がヒットしない
    トピック投稿者 m0810

    (@m0810)

    function.phpの記述を1つずつ消して検証したと思っていましたが、
    指摘のあった「pre_get_posts」1か所削除で問題なく動作出来ました。

    コピペで使用していたので何処かの際で設定したのを忘れてしまっていたようでした;;;

    協力いただきました、mypacecreatorさんとmunyaguさん
    ありがとうございました。

    フォーラム: 使い方全般
    返信が含まれるトピック: サイト内検索で記事がヒットしない
    トピック投稿者 m0810

    (@m0810)

    あ・・・

    フォーラム: 使い方全般
    返信が含まれるトピック: サイト内検索で記事がヒットしない
    トピック投稿者 m0810

    (@m0810)

    返信ありがとうございます。

    追記の内容拝見しました。
    カスタム投稿の記述で正常に動作するということは・・・もしかしたらその他の「function.php」で検索を無効させる何かがあるのでしょうか・・・。

    一応、function.phpの全文を載せておきます。
    —————————————————
    <?php
    // 記事内の画像の1枚目を取得する
    function getPostImage($mypost){
    if(empty($mypost)){ return(null); }
    if(ereg(‘<img([ ]+)([^>]*)src\=[“|\’]([^”|^\’]+)[“|\’]([^>]*)>’,$mypost->post_content,$img_array)){
    // imgタグで直接画像にアクセスしているものがある
    $dummy=ereg(‘<img([ ]+)([^>]*)alt\=[“|\’]([^”|^\’]+)[“|\’]([^>]*)>’,$mypost->post_content,$alt_array);
    $resultArray[“url”] = $img_array[3];
    $resultArray[“alt”] = $alt_array[3];
    }
    else{
    // 直接imgタグにてアクセスされていない場合は紐づけられた画像を取得
    $files = get_children(array(‘post_parent’ => $mypost->ID, ‘post_type’ => ‘attachment’, ‘post_mime_type’ => ‘image’));
    if(is_array($files) && count($files) != 0){
    $files=array_reverse($files);
    $file=array_shift($files);
    $resultArray[“url”] = wp_get_attachment_url($file->ID);
    $resultArray[“alt”] = $file->post_title;
    }
    else{
    return(null);
    }
    }
    return($resultArray);
    }

    // カスタム投稿「宿泊施設」
    function my_custom_init() {
    register_post_type( ‘stay’, array(
    ‘label’ => ‘宿泊施設’,
    ‘public’ => true,
    ‘supports’ => array( ‘title’, ‘editor’, ‘author’, ‘thumbnail’, ‘excerpt’, ‘custom-fields’ ,’comments’ ),
    ‘menu_position’ => 5,
    ‘has_archive’ => true,
    ‘rewrite’ => true,
    ));
    }
    add_action( ‘init’, ‘my_custom_init’ );
    $args = array(
    ‘label’ => ‘カテゴリー’,
    ‘public’ => true,
    ‘show_ui’ => true,
    ‘hierarchical’ => true,
    );
    register_taxonomy(‘staylist’, ‘stay’, $args);
    $categories = get_the_terms($post_id, ‘staylist’);

    // カスタム投稿「体験」
    function my_custom_init2() {
    register_post_type( ‘experience’, array(
    ‘label’ => ‘体験’,
    ‘public’ => true,
    ‘supports’ => array( ‘title’, ‘editor’, ‘author’, ‘thumbnail’, ‘excerpt’, ‘custom-fields’ ,’comments’ ),
    ‘menu_position’ => 5,
    ‘has_archive’ => true,
    ‘rewrite’ => true,
    ));
    }
    add_action( ‘init’, ‘my_custom_init2’ );
    $args = array(
    ‘label’ => ‘カテゴリー’,
    ‘public’ => true,
    ‘show_ui’ => true,
    ‘hierarchical’ => true,
    );
    register_taxonomy(‘experiencelist’, ‘experience’, $args);
    $categories = get_the_terms($post_id, ‘experiencelist’);

    // ウィジェット使用
    if ( function_exists( ‘register_sidebar’ ) ){
    register_sidebar();
    }

    // アイキャッチ画像使用
    add_theme_support(‘post-thumbnails’);

    // 1件目の記事情報取得
    function isFirst(){
    global $wp_query;
    return ($wp_query->current_post === 0);
    }

    // 行頭の全角スペースを許可
    add_filter(‘tiny_mce_before_init’, ‘my_tiny_mce_before_init_filter’,10,3);
    function my_tiny_mce_before_init_filter( $init_array ) {
    $init_array[‘remove_linebreaks’] = false;
    return $init_array;
    }

    // 抜粋記事のショートコード表示を非表示
    function my_noshotcode($content){
    $rtn = “”;
    preg_match(“/\[.+?\]/”,$content,$retArr);
    $rtn = str_replace($retArr[0],”,$content);
    return $rtn;
    }

    // 自動で入る<p>を非表示
    function SearchExcludeCategoryFilter($query) {
    if ($query->is_search) { $query->set(‘cat’,’1′); }
    return $query;
    }
    add_filter(‘pre_get_posts’,’SearchExcludeCategoryFilter’);
    add_action(‘init’, function() {
    remove_filter(‘the_excerpt’, ‘wpautop’);
    remove_filter(‘the_content’, ‘wpautop’);
    });
    add_filter(‘tiny_mce_before_init’, function($init) {
    $init[‘wpautop’] = false;
    $init[‘apply_source_formatting’] = ture;
    return $init;
    });

    // カスタムフィールドのGoogleMAPのAPIキー
    function my_acf_google_map_api( $api ){
    $api[‘key’] = ‘XXXXXX’;
    return $api;
    }
    add_filter(‘acf/fields/google_map/api’, ‘my_acf_google_map_api’);

    //カスタム投稿用post_typeセット(カスタム投稿別に検索範囲をセットする)
    add_filter(‘template_include’,’custom_search_template’);
    function custom_search_template($template){
    if ( is_search() ){
    $post_types = get_query_var(‘post_type’);
    foreach ( (array) $post_types as $post_type )
    $templates[] = “{$post_type}-search.php”;
    $templates[] = ‘search.php’;
    $template = get_query_template(‘search’,$templates);
    }
    return $template;
    }

    ?>
    —————————————————

    自分のPHPソースの記述に原因があるのか引き続き続けていきます。

    因みにですが、jQueryを幾つか導入しているのでもしかしたらその部分…というのも考えられるのでしょうか?
    現在使用中のjQueryを書いておきます。
    1.「bxslider」
    2.「fatNav」
    3.「smoothScroll」

    • この返信は7年、 2ヶ月前にm0810が編集しました。
    フォーラム: 使い方全般
    返信が含まれるトピック: サイト内検索で記事がヒットしない
    トピック投稿者 m0810

    (@m0810)

    本日確認できたところを追記。

    1.自作の検索結果のソースを「Twenty Seventeen」からコピペしたが、検索はヒットしない。

    2.使用していたプラグインを全て停止、削除したが検索はヒットしない。

    テーマを変更すると検索が動作するので、もしかしたら自作でカスタム投稿を作成した部分に問題があるのか??

    引き続き検証していきます

    フォーラム: 使い方全般
    返信が含まれるトピック: サイト内検索で記事がヒットしない
    トピック投稿者 m0810

    (@m0810)

    返信が遅くなりました。
    確認できた部分を追記いたします。

    1.一旦別のテーマにして検索を確認する。
    「Twenty Seventeen」(バージョン: 1.5)にしたところ検索が問題なく動作しました。

    2.管理画面の投稿一覧右上の「投稿を検索」の動作を確認する。
     自作テーマの場合⇒記事がヒットしない
     「Twenty Seventeen」(バージョン: 1.5)のテーマの場合⇒投稿記事がヒットする

    ここまででわかったことが・・・
    自作の検索結果のソースに不備がある or 「Advanced Custom Fields」の不具合??
    確認する部分がだんだん絞り込めてきていますが、最終的な原因発見に向けて検証を続けていきます。

    フォーラム: 使い方全般
    返信が含まれるトピック: サイト内検索で記事がヒットしない
    トピック投稿者 m0810

    (@m0810)

    返答頂きありがとうございます。

    1.「search.php」の全文は現在このような状態です。
    ———————————————-
    <?php get_header(“3″); ?>

    <div class=”body-main”>
    <div>【サイト内検索】</div>

    <div class=”contact-body”>

    <div class=”title”>
    <?php $allsearch =& new WP_Query(“s=$s&posts_per_page=-1”);
    $key = wp_specialchars($s, 1);
    $count = $allsearch->post_count;
    if($count!=0){
    // 検索結果を表示:該当記事あり
    echo ‘<p>“‘.$key.’”で検索した結果、‘.$count.’件の記事が見つかりました</p>’;
    }
    else {
    // 検索結果を表示:該当記事なし
    echo ‘<p>“‘.$key.’”で検索した結果、関連する記事は見つかりませんでした</p>’;
    }
    ?>
    </div>

    <?php if (have_posts()) : ?>
    <?php while (have_posts()) : the_post(); ?>
    <!– Start: Post –>
    <div class=”post section”>

    <h3>“><?php the_title(); ?></h3>
    <p class=”post-meta”>
    <span class=”date”><?php the_time(‘Y年m月d日(D)’); ?></span>
    </p>

    <div class=”entry”>
    <?php the_post_thumbnail(); ?>
    <?php the_excerpt(); ?>
    </div>
    <div class=”clear-both”></div>

    <?php if(has_tag()): ?><p class=”tags”><span><?php the_tags(“”); ?></span></p><?php endif; ?>

    </div>
    <!– End: Post –>
    <?php endwhile; ?>

    <div class=”navigation”>
    <?php if(function_exists(‘wp_page_numbers’)) { wp_page_numbers(); } ?>
    </div>
    <?php else : ?>
    <div class=”post section”>
    <p>お探しのキーワードは見つかりません。</p>
    </div>
    <?php endif; ?>

    </div>
    <div class=”clear”></div>

    </div>

    <?php get_footer(); ?>
    ———————————————-

    2.「カスタム投稿」は下記の記述で作成しています(functions.phpに記述)
    ———————————————-
    // カスタム投稿「宿泊施設」
    function my_custom_init() {
    register_post_type( ‘stay’, array(
    ‘label’ => ‘宿泊施設’,
    ‘public’ => true,
    ‘supports’ => array( ‘title’, ‘editor’, ‘author’, ‘thumbnail’, ‘excerpt’, ‘custom-fields’ ,’comments’ ),
    ‘menu_position’ => 5,
    ‘has_archive’ => true,
    ‘rewrite’ => true,
    ));
    }
    add_action( ‘init’, ‘my_custom_init’ );
    $args = array(
    ‘label’ => ‘カテゴリー’,
    ‘public’ => true,
    ‘show_ui’ => true,
    ‘hierarchical’ => true,
    );
    register_taxonomy(‘staylist’, ‘stay’, $args);
    $categories = get_the_terms($post_id, ‘staylist’);

    // カスタム投稿「体験」
    function my_custom_init2() {
    register_post_type( ‘experience’, array(
    ‘label’ => ‘体験’,
    ‘public’ => true,
    ‘supports’ => array( ‘title’, ‘editor’, ‘author’, ‘thumbnail’, ‘excerpt’, ‘custom-fields’ ,’comments’ ),
    ‘menu_position’ => 5,
    ‘has_archive’ => true,
    ‘rewrite’ => true,
    ));
    }
    add_action( ‘init’, ‘my_custom_init2’ );
    $args = array(
    ‘label’ => ‘カテゴリー’,
    ‘public’ => true,
    ‘show_ui’ => true,
    ‘hierarchical’ => true,
    );
    register_taxonomy(‘experiencelist’, ‘experience’, $args);
    $categories = get_the_terms($post_id, ‘experiencelist’);

    3.標準の投稿が「グリーン通信」。
      カスタム投稿が「体験」と「宿泊施設」になります。

    フォーラム: 使い方全般
    返信が含まれるトピック: サイト内検索で記事がヒットしない
    トピック投稿者 m0810

    (@m0810)

    回答ありがとうございます。

    環境について追記します。
    ■サーバー:GMOクラウド(レギュラー)
    ■Wordpressバージョン:4.9.5
    ■使用プラグイン:
    ・Advanced Custom Fields
    ・Google XML Sitemaps
    ・Imsanity
    ・WP Multibyte Patch
    ・WP-PageNavi

    ◎カスタム投稿を2つ作成しました。(合計3つの投稿を現在は使用中)
    ◎「searchform.php」を自作
     ———————————-
    <form method=”get” action=”<?php echo home_url(‘/’); ?>” >
    <input name=”s” type=”text”>
     ———————————-
    ◎「search.php」を作成
    ————————————
    <?php $allsearch =& new WP_Query(“s=$s&posts_per_page=-1”);
    $key = wp_specialchars($s, 1);
    $count = $allsearch->post_count;
    if($count!=0){
    // 検索結果を表示:該当記事あり
    echo ‘<p>“‘.$key.’”で検索した結果、‘.$count.’件の記事が見つかりました</p>’;
    }
    else {
    // 検索結果を表示:該当記事なし
    echo ‘<p>“‘.$key.’”で検索した結果、関連する記事は見つかりませんでした</p>’;
    }
    ?>
    ————————————

    自分で確認した部分では、Wordpress管理画面上の投稿一覧の検索(右上)でも結果にはヒットしませんでした。
    「Hello…」の投稿だけはヒットしていましたが、一旦記事を削除して再度作成したものはヒットしなくなりました。
    気になる部分と言えば、制作途中でSSLの申請をしたので途中からURLがSSLに変わった事です。
    (WordpressインストールはSSLになる前に行っております)

    「functions.php」には、カスタム投稿を作成する記述ぐらいしか記入しておりません。
    (現に同じソースの別のサイトだと検索は問題なく動きます)
    (exclude_from_searchはソース上にないです)

    自分でも1つずつ確認している現状です。

7件の返信を表示中 - 1 - 7件目 (全7件中)