0

正常搜索工作正常,但我需要根据 wordpress 中的类别进行搜索。例如..假设我有两个名为“汽车”和“公共汽车”的类别,如果我选择汽车类别,那么搜索应该显示汽车类别的结果,如果我选择了公共汽车类别,那么搜索应该显示公共汽车类别的结果。

截至目前我正在使用此代码

<?php wp_dropdown_categories('show_option_all='.__('All Categories',        'appthemes').'&hierarchical='.get_option('cp_cat_hierarchy').'&hide_empty='.get_option('cp_    cat_hide_empty').'&depth='.get_option('cp_search_depth').'&show_count='.get_option('cp_cat_    count').'&pad_counts='.get_option('cp_cat_count').'&orderby=name&title_li=&use_desc_for_tit    le=1&tab_index=2&name=scat&selected='.cp_get_search_catid().'&class=searchbar&taxonomy='.AP    P_TAX_CAT); ?>

此代码在 Classipress 主题中使用

谢谢肖比特

4

1 回答 1

1

有几种方法可以实现这一点,您必须用下面的代码替换 searchform.php 中的标准 WordPress 搜索表单。

这将启用基于类别的搜索。

<form role="search" method="get" id="searchform" action="<?php bloginfo('siteurl'); ?>">
<div>
<label class="screen-reader-text" for="s">Search for:</label>
<input type="text" value="" name="s" id="s" /> 
in <?php wp_dropdown_categories( 'show_option_all=All Categories' ); ?> 
<input type="submit" id="searchsubmit" value="Search" />
</div>
</form>
于 2012-09-11T08:26:21.130 回答