这是一个基于答案评论的问题here.
我正在使用以下代码为我的网站创建两个不同的搜索框:
<form action="<?php echo home_url( \'/glossary/\' ); ?>" method="get">
<p style="font-size:12px;">SEARCH<strong class="dkblue">GLOSSARY</strong></p>
<input type="text" name="s" value="" />
<input type="submit" value="GO" class="glossary_submit" />
</form>
<form id="profilesearch" action="<?php echo home_url( \'/species/\' ); ?>" method="get">
<input type="text" size="50" class="default-value" value="SEARCH" name="s" />
<input type="submit" value="GO" class="profilesearch_submit" />
<!-- <p class="tinysearch"><a href="/dev/advanced-search/">ADVANCED SEARCH</a></p> -->
<input type="checkbox" name="showthumbnails" id="showthumbnails" class="checkbox" <?php if ($_POST["showthumbnails"] == "on") { echo \'checked="checked" \'; } ?>/><label for="showthumbnails">HIDE THUMBNAILS</label>
</form>
我的glossary
CPT有以下创建$args
:$args = array(
\'labels\' => $labels,
\'public\' => true,
\'publicly_queryable\' => true,
\'exclude_from_search\' => true,
\'show_ui\' => true,
\'show_in_menu\' => true,
\'query_var\' => true,
\'capability_type\' => \'post\',
\'has_archive\' => false,
\'hierarchical\' => true,
\'menu_position\' => 40,
\'menu_icon\' => $this->plugin_url . \'images/glossary.png\',
\'supports\' => array(\'title\',\'editor\',\'thumbnail\',\'page-attributes\')
);
还有我的species
CPT有:$args = array(
\'labels\' => $labels,
\'public\' => true,
\'publicly_queryable\' => true,
\'show_ui\' => true,
\'show_in_menu\' => true,
\'query_var\' => true,
\'has_archive\' => true,
\'capability_type\' => \'post\',
\'has_archive\' => true,
\'hierarchical\' => false,
\'menu_position\' => 5,
\'menu_icon\' => $this->plugin_url . \'images/fish20.png\',
\'supports\' => array(\'author\',\'thumbnail\',\'excerpt\',\'comments\',\'revisions\')
);
目前,当我从词汇表表单提交搜索时,URL更改为:/glossary/?s=term
. 当我从物种表单提交搜索时,URL更改为:/search/term
. 词汇表URL的作用是搜索glossary
仅限CPT类型。然而,物种URL只是搜索所有内容。
If I change has_archive
to false
, the searches work as per the above glossary
. If I change it to true
, the searches work as per the above species
.
/search/cpt-slug/term
, i、 e。/search/species/bettas
并仅搜索具有该CPT的帖子。我有没有做错什么$args
?