Wordpress/Woo how to search in category?

2019-08-10 13:53发布

In Wordpress / WooCommerce I want to search by Category but somehow I cant get it to work. The normal Search works and gives me this url http://localhost:8888/rwdr/search/[searchkeyword] how does the url look like when searching in a category?

<form role="search" method="get" id="searchform2" action="" class="">
    <ul class="radio-ul">
      <li>
        <label for="typBA" class="typ typBA "></label>
        <input name="category" id="typBA" value="BA" type="radio">
      </li>
      <li>
        <label for="typBAX7" class="typ typBAX7 "></label>
        <input name="category" id="typBAX7" value="BAX7" type="radio">
      </li>
      <li>
        <label for="typBASL" class="typ typBASL "></label>
        <input name="category" id="typBASL" value="BASL" type="radio">
      </li>
    </ul>

    <label for="InputBox">Input Box</label>
    <input type="text" value="" id="first" name="s" />
    <input type="hidden" value="" name="x" /> </form>

I really appreciate any help!

2条回答
贪生不怕死
2楼-- · 2019-08-10 14:42

You can do a search using standard query in your url

yoursite.com/?post_type=product&taxonomy=product_cat&term=your_category_slug&s=a

To get the URL, you can build a form like this,

<form method="get" action="" role="search">
    <input type="hidden" name="post_type" value="product">
    <input type="hidden" name="taxonomy" value="product_cat">
    <input type="hidden" name="term" value="your_category_slug">
    <input type="search" name="s" value="">
    <input type="submit" value="Search">
</form>
查看更多
\"骚年 ilove
3楼-- · 2019-08-10 14:54

In WordPress, I use a plugin called "Search Everything", where you can set if you want to add categories, tags and many other options to the search results. It's pretty easy to use and it works fine to me.

查看更多
登录 后发表回答