いつも大変お世話になっております。
今回はWordPressについて質問させてください。
###前提・サイトに使用しているWordPressの標準検索機能をカスタマイズしたい
先頃、とある企業様のウェブサイトをリニューアルしまして、
その際にサイト内検索機能を追加しました。
WordPressの標準機能である検索機能を利用しております。
検索結果のビジュアル部分は対応できたのですが、
肝心の内容をカスタマイズする段階で困っています。
###発生している問題・エラーメッセージ
検索結果に出て来て欲しくないカスタム投稿記事を除外する方法が分かりません。
本サイトの仕様上、いくつか存在するカスタム投稿タイプは以下の形態をとっています。
1. 通常のHTML形式での投稿 2. 添付したPDFファイルへのリンクのみ 3. サイト更新のお知らせ(サイト内別ページへのリンクのみ)
この内、1.のみを検索結果に表示させ、2.と3.は除外したいのですが、
その方法が分かりません。
meta_queryを使用して除外するのだとは思うのですが、
それを標準検索にどのように組み込めばいいのかが分からない状況です。
どなたか解決策をご存じの方はおられませんでしょうか?
よろしくお願いします。
###補足情報1(言語/FW/ツール等のバージョンなど)
使用サーバ:
さくらインターネット レンタルサーバ ビジネスプロ
OSバージョン:
FreeBSD 9.1-RELEASE-p24 amd64
Apacheバージョン:
Apache/2.4.33
WordPressバージョン:4.9.8
###補足情報2(search.phpの内容)
marlboro_tataさんからご指摘がありました。ありがとうございます。
search.phpの内容を転記いたします。
<?php /** * The template for displaying search results pages * * @package WordPress * @subpackage Twenty_Sixteen * @since Twenty Sixteen 1.0 */ get_header(); ?> <!--<section id="primary" class="content-area"> <main id="main" class="site-main" role="main">--> <section> <?php if ( empty( get_search_query() ) ) { // 検索キーワードがないとき echo '<p>検索キーワードが未入力です。</p>'; }else{ ?> <?php if ( have_posts() ) { $max_num_pages = $wp_query->max_num_pages; ?> <!-- <header class="page-header"> <h1 class="page-title"><?php printf( __( 'Search Results for: %s', 'twentysixteen' ), '<span>' . esc_html( get_search_query() ) . '</span>' ); ?></h1> </header>--> <!-- .page-header --> <p><?php printf( __( 'キーワード「%s」の検索結果です', 'twentysixteen' ), '<span>' . esc_html( get_search_query() ) . '</span>' ); ?></p> <ul class="text-list"> <?php // Start the loop. while ( have_posts() ) :the_post(); echo '<li>'; echo '<a href="'; the_permalink(); echo '">'; echo '<h3>'; the_title(); echo '</h3>'; echo '<p>'; the_excerpt(); echo '</p>'; echo '</a></li>'; /** * Run the loop for the search to output the results. * If you want to overload this in a child theme then include a file * called content-search.php and that will be used instead. */ //get_template_part( 'template-parts/content', 'search' ); // End the loop. endwhile; echo '</ul>'; // Previous/next page navigation. /* the_posts_pagination( array( 'prev_text' => __( 'Previous page', 'twentysixteen' ), 'next_text' => __( 'Next page', 'twentysixteen' ), 'before_page_number' => '<span class="meta-nav screen-reader-text">' . __( 'Page', 'twentysixteen' ) . ' </span>', ) ); */ if (function_exists("pagination")) { pagination(3, $max_num_pages); } // If no content, include the "No posts found" template. }else{ //get_template_part( 'template-parts/content', 'none' ); //echo '<p>記事がありません。</p>'; echo '<p>'.'キーワード「<span>'.esc_html(get_search_query()).'</span>」に該当するページはありません。</p>'; } } ?> <!--</main>--><!-- .site-main --> </section><!-- .content-area --> <?php get_footer(); ?>