自定义帖子类型搜索模板


Custom Post Type Search Template

目前我有 1 个称为"指南"的自定义帖子类型和几个自定义字段。现在我想在存档指南上显示一个搜索表单.php您可以在其中搜索自定义字段冠军。

这是我在存档指南中的代码:

<form id="searchform" action="<?php bloginfo('home'); ?>/" method="get">
    <input id="s" maxlength="150" name="s" size="20" type="text" value="" class="txt" />
    <input name="post_type" type="hidden" value="guides" />
    <input id="searchsubmit" class="btn" type="submit" value="Search" />
</form>

这是我在搜索中的代码.php:

<?php 
$search_refer = $_GET["post_type"];
if ($search_refer == 'guides') {
    if ('meta_key=champion&meta_value=$search_query') {     load_template(TEMPLATEPATH . '/search-guides.php'); } };
?>

但它仍然不会重定向到搜索指南.php,如果我使用表单进行搜索,网址将变得/?s=query&post_type=guides(查询=搜索词)。

任何帮助表示赞赏!

我认为 https://wordpress.stackexchange.com/questions/89886/how-to-create-a-custom-search-for-custom-post-type 帖子将帮助您创建自定义帖子类型的自定义搜索。

也有帮助:http://www.wpbeginner.com/wp-tutorials/how-to-create-advanced-search-form-in-wordpress-for-custom-post-types/

请更新您的代码以进行load_template。