Wordpress基于类别的搜索


Wordpress category based search

正常搜索工作正常,但我需要在wordpress中根据类别进行搜索。例如。。假设我有两个类别,分别命名为"汽车"answers"公共汽车",如果我选择Car类别,则搜索应显示来自Car类别的结果;如果我选择了Bus类别,则检索应显示来自公共汽车类别的结果。

截至目前,我使用此代码

<?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主题中使用

谢谢Shobhit

有几种方法可以实现这一点——你必须用下面的代码替换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>