如果它是默認的WordPress搜索或自定義搜索表單,則僅匹配帖子標題,類別和標籤中的搜索文本。僅限於文章標題,類別和標籤的搜索結果
0
A
回答
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…">
<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;
}
?>
相關問題
- 1. solr搜索多個類別和標籤
- 2. 用標籤顯示文章的類別
- 3. 基於類別的搜索結果
- 4. 識別文章標籤
- 5. Laravel搜索標題和相關標籤
- 6. Drupal僅搜索標題
- 7. 從基於標籤的搜索引擎返回結果
- 8. 別名`grep的-w「標籤for'`僅搜索第一個詞(標籤)
- 9. WordPress的:結合類別和標籤
- 10. 如何添加標題類別名稱,如果不存在,在文章標題
- 11. 使一個特定類別的wordpress標籤雲鏈接到該類別和標籤的文章列表
- 12. 搜索結果中的散列表標誌搜索結果
- 13. 全文搜索 - 標籤系統問題
- 14. 搜索標籤
- 15. Rails 3 - 限制文章標籤
- 16. 快速多標籤搜索加結果排序和分頁?
- 17. 搜索多個標籤的文章 - 休眠許多一對多
- 18. 如何對搜索結果的HTML表單標籤效果
- 19. WooCommerce:按標題,類別,標籤或品牌搜索產品不起作用
- 20. 顯示搜索結果,點擊上的藝術家和標題
- 21. WordPress的搜索結果 - 檢查自定義文章類型
- 22. NetSuite保存的搜索列標題/標題。使用SQL標籤
- 23. 如何防止Joomla在從搜索結果和latestnews模塊鏈接的文章中添加h1標籤?
- 24. 「模糊」帖子標籤和帖子標題搜索mysql和php
- 25. Rails - 資本化文章標籤和標題
- 26. 如何從搜索結果中隱藏標籤和分類鏈接?在wordpress
- 27. 如何按類別和標籤過濾WordPress結果?
- 28. woocommerce僅搜索基於主體類別的父類別產品
- 29. Kentico - 僅限內容頁面和智能搜索結果
- 30. CSS - 搜索結果 - 圖片,標題和描述
號我問結果取,不覆蓋默認搜索模板。 – GNANA