1

我将以下代码添加到我网站上的 php 小部件中,以便通过下拉框按产品类别搜索网站。

<form role="search" method="get" id="searchform" action="<?phpbloginfo('siteurl'); ?>"<div>
<label class="screen-reader-text" for="s">Search for:</label>
<input type="text" value="" name="s" id="s" />
<?php wp_dropdown_categories ($args = array(
'taxonomy' => 'product_cat',)); ?>
<input type="submit" id="searchsubmit" value="Search" /></div></form>

我无法弄清楚为什么任何搜索都没有返回任何命中。当我查看搜索结果时,似乎有些不对劲。我只看到搜索词和类别编号 (example="?s=flour&cat=17") 任何关于从哪里开始阅读的指导都非常感谢。

4

2 回答 2

0

使用 pre_get_posts 过滤器更改搜索查询

欲了解更多信息,请查看以下链接

https://codex.wordpress.org/Plugin_API/Action_Reference/pre_get_posts

于 2015-09-28T10:12:56.203 回答
0

默认情况下,在执行搜索查询时,WordPress 不会搜索自定义帖子类型,为了解决您面临的问题,请将以下隐藏字段添加到您的小部件表单定义中

<input type="hidden" value="product" name="post_type">

于 2015-09-28T06:27:50.450 回答