2017-06-06 209 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

搜索表單應該這樣。 {} post_type .PHP -

<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> 

我們將使用{}模板的WordPress的文件名命名慣例我們的定製搜索結果模板。在我們的例子中,這將導致search-kb_article.php。我們可以檢查是否在URL字符串中設置了post_type = kb_article,如果是,則使用get_template_part加載它,但讓我們更進一步。我們將檢查是否在URL字符串中設置了post_type,如果是,則使用{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

相關問題