2017-06-06 14 views

答えて

0

使用は

$args = array(
      'post_type' => 'post', 
      's' => $keyword, 
      'cat' => $catSearchID, 
      'tag' => $tag-slug, 
      'posts_per_page' => -1, 
      'location' => $post_location_search , 
     ); 

$wp_query = new WP_Query($args); 
0

検索フォームはこのようになります。

<form class="search" action="<?php echo home_url('/'); ?>"> 
    <input type="search" name="s" placeholder="Search&hellip;"> 
    <input type="submit" value="Search"> 
    <input type="hidden" name="post_type" value="kb_article"> 
</form> 

{template} - {post_type} .phpのWordPressファイル名規則を使用してカスタム検索結果テンプレートの名前を付けます。私たちの場合、それはsearch-kb_article.phpになります。 post_type = kb_articleがURL文字列に設定されているかどうかを確認し、もしあればそれをロードするためにget_template_partを使用しますが、さらに進んでみましょう。存在する場合は、{template} - {post_type} .phpという名前のパターンを使用して、その投稿タイプにカスタム検索テンプレートが存在するかどうかを確認します。そうであれば、ロードします。そうでない場合は、デフォルトの検索テンプレートを使用します。クエリ以下

<?php 
// store the post type from the URL string 
$post_type = $_GET['post_type']; 
// check to see if there was a post type in the 
// URL string and if a results template for that 
// post type actually exists 
if (isset($post_type) && locate_template('search-' . $post_type . '.php')) { 
    // if so, load that template 
    get_template_part('search', $post_type); 

    // and then exit out 
    exit; 
} 
?> 
+0

いいえ、私が求めていた結果では、デフォルトの検索テンプレートを上書きしないように、フェッチ、解決策を得ることができます。 – GNANA

関連する問題